I can't figure out why I'm getting HTTP status code 409. I'm trying to
add new contacts using Zend's Gdata class.
Here's my code:
<?php
require_once('Zend/Loader.php');
require_once('DeafForm.php');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
class BasicContact {
const SERVICE_NAME = "cp";
const APPLICATION_NAME = "basic_contact-test";
const USERNAME = "
hello...@gmail.com"; //censored!
const PASSWORD = "fake-password"; //censored!
protected $httpclient;
protected $gdata;
protected $form;
protected $mystream;
public function __construct(){
$this->httpclient = Zend_Gdata_ClientLogin::getHttpClient
(self::USERNAME, self::PASSWORD, self::SERVICE_NAME, null,
self::APPLICATION_NAME);
$this->gdata = new Zend_Gdata($this->httpclient);
$this->mystream = "
http://www.google.com/m8/feeds/contacts/
default/full";
}
public function addContact($form){
$entry = $this->gdata->newEntry();
$extensionElement = $entry->getExtensionElements();
$attributes = array();
//set contact's name
$entry->title = $this->gdata->newTitle($form-
>getSubmitterFirstName()." ".$form->getSubmitterLastName());
//generate email address
$extension = new Zend_Gdata_App_Extension_Element('email', null,
'
http://schemas.google.com/g/2005');
$attr['address'] = array('name' => 'address', 'value' =>
$emailaddy, 'namespaceUri' => null);
$attr['primary'] = array('name' => 'primary', 'value' => 'true',
'namespaceUri' => null);
$attr['rel'] = array('name' => 'rel', 'value' => 'http://
schemas.google.com/g/2005#other', 'namespaceUri' => null);
$extension->setExtensionAttributes($attributes);
//update/add to contacts
$entry->setExtensionElements(array($extension));
$entryResult = $this->gdata->insertEntry($entry, $this-
>mystream);
}
}
?>
And here's the error message:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with
message 'Expected response code 200, got 409 <?xml version='1.0'
encoding='UTF-8'?><entry xmlns='
http://www.w3.org/2005/Atom'
xmlns:gContact='
http://schemas.google.com/contact/2008'
xmlns:batch='
http://schemas.google.com/gdata/batch' xmlns:gd='http://
schemas.google.com/g/2005'><id>
http://www.google.com/m8/feeds/contacts/
randalln.spam%
40gmail.com/base/207d23568a39769d</
id><updated>2009-07-30T20:52:06.922Z</updated><category scheme='http://
schemas.google.com/g/2005#kind' term='
http://schemas.google.com/
contact/2008#contact'/><title type='text'>Randall Noriega</title><link
rel='
http://schemas.google.com/contacts/2008/rel#edit-photo'
type='image/*' href='
http://www.google.com/m8/feeds/photos/media/
randalln.spam%
40gmail.com/207d23568a39769d/1B2M2Y8AsgTpgAmY7PhCfg'/
><link rel='self' type='application/atom+xml' href='http://
www.google.com/m8/feeds/contacts/randalln.spam%40gmail.com/full/207d23568a39769d'/><link
rel='edit' type='application/atom+xml' href='http:/ in /usr/local/etc/
ZendGdata-1.8.4PL1/library/Zend/Gdata/App.php on line 699
I'm stumped at this point. Hope you guys can help solve my problem.
Thanks in advance, guys!