-->

“If-Match or If-None-Match header or entry etag at

2020-03-30 06:31发布

问题:

Hi guys I'm trying to update my google contacts using the zend framework but I'm getting the following error:

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

The following is my code:

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

$client = getGoogleClient('cp'); // this is a function I made - its working fine
$client->setHeaders('If-Match: *');

$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query($id);// id is the google reference 

$entry = $gdata->getEntry($query);
$xml = simplexml_load_string($entry->getXML());

$xml->name->fullName = trim($contact->first_name).' '.trim($contact->last_name);

$entryResult = $gdata->updateEntry($xml->saveXML(), $id);

Whats going on?

回答1:

i got a solution in http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14476692

here is the message from that link:

// in listing 6... // somewhere before the updateEntry call add: $extra_header = array(); $extra_header='*';

// and then replace the current updateEntry call with the following: $entryResult = $gdata->updateEntry($xml->saveXML(),$entry->getEditLink()->href,null,$extra_header);

Updates to Google Contacts now work.

i get it work for my code. again there is a problem with the code in the post as well. that is

$extra_header = array(); 

$extra_header = array('If-Match'=>'*'); 

$entryResult  = $contactObj->updateEntry($xml->saveXML(),$entry->getEditLink()->href,null,$extra_header);

I think it will help you solve the update problem as well.

thanks