2

I have problem with Zend framework. I'm trying to delete single contact from google's server. I have class:

class GContacts
{
    const BASE_FEED_URI = 'https://www.google.com/m8/feeds';

    private $client = NULL;
    private $gData = NULL;
    private $contScope = '';
    private $groupScope = '';

    public function __construct($userName,$pass){       
        ini_set('include_path', LIB_DIR);
        require_once('\Zend\Loader.php');

        Zend_Loader::loadClass('Zend_Gdata');
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
        Zend_Loader::loadClass('Zend_Http_Client');
        Zend_Loader::loadClass('Zend_Gdata_Query');
        Zend_Loader::loadClass('Zend_Gdata_Feed');          

        $this -> client = Zend_Gdata_ClientLogin::getHttpClient($userName, $pass, 'cp');
        $this -> gData = new Zend_Gdata($this -> client);
        $this -> gData -> setMajorProtocolVersion(3);

        $this -> contScope = self :: BASE_FEED_URI . '/contacts/' . urlencode($userName);
    }

    public function addContact($cont){
        $doc = new DOMDocument();
        $doc -> formatOutput = true;

        // header
        $entry = $doc -> createElement('atom:entry');
        $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:atom', 'http://www.w3.org/2005/Atom');
        $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', 'http://schemas.google.com/g/2005');
        $entry -> setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gContact', 'http://schemas.google.com/contact/2008');
        $doc -> appendChild($entry);

        // add name element
        $name = $doc -> createElement('gd:name');
        $entry -> appendChild($name);
        $fullName = $doc -> createElement('gd:fullName', 'John Doe');
        $name -> appendChild($fullName);

        // insert entry
        $addResult = $this -> gData -> insertEntry($doc -> saveXML(), 'http://www.google.com/m8/feeds/contacts/default/full');

        return $this -> parseUniqueId($addResult -> id);
    }

    public function delete($gid){
        // Should be some work with Etag, but Zend is buggy and it doesn't work
        $entry = $this -> gData -> getEntry($this -> contScope . '/full/' . $gid);
        $entry -> delete();
    }

    private function parseUniqueId($link){
        $arr = explode('/',$link);
        return end($arr);
    }
}

And calling:

$gCont = new GContacts($userName,$pass);

$gid = $gCont -> addContact('param will be soon');
$gCont -> delete($gid);

Here is the problem (in delete method):

  • Expected response code 200, got 403 If-Match or If-None-Match header or entry etag attribute required

I HAVE TO use google Etag handling, because there are more than one person with access to this contacts, so I can't use this or advice here in Zend bugreport. Have anyone idea how to solve it?

Thank a lot! Ajax

EDIT: This bug is not fixed at all, Is here anyone with this problem? I'm desperate.. :(

Community
  • 1
  • 1
Ajax
  • 576
  • 2
  • 8
  • 21

1 Answers1

0

I have the solution.

There is a BUG in Zend\Gdata\App.php

Line 547 (on version 1.12.6), add the line $headers['If-Match'] = '*'; in the if condition. Now, you should have :

if ($method == 'DELETE') {
    $rawData = null;
    $headers['If-Match'] = '*';
}

Keep me in touch ;)

Jerry
  • 1,141
  • 1
  • 13
  • 18
  • Hello! Thanks for your answer. This project with Google contacts has been skipped. Just now, I'm working on something quite different and I can't test it. But thanks for your answer, I'm sure I'll you it in the future... – Ajax Jun 04 '14 at 07:59