I am having the same issue. The code below is what I've come up with. It
is adding the contact and details, but I can't get it to add the contact to
the specified group. Can someone have a look at my code? Thank you in
advance!
<?php
include('../config.php');
include('../common_functions.php');
$query = "SELECT * FROM `Customers` WHERE (Priority1 = '1' OR Priority2 =
'1' OR Priority3 = '1' )";
$result = mysql_execute($query);
// load Zend Gdata libraries
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');
// set credentials for ClientLogin authentication
$user = "[email protected]";
$pass = "mypassword1234";
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient(
$user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
while($row = mysql_fetch_array($result))
{
// create new entry
$doc = new DOMDocument();
$doc->formatOutput = true;
$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/g/2005');
$doc->appendChild($entry);
// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);
$fullName = $doc->createElement('gd:fullName', $row['FirstName']."
".$row['LastName']);
$name->appendChild($fullName);
// add email element
$email = $doc->createElement('gd:email');
$email->setAttribute('address' ,$row['EmailAddress']);
$email->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
$entry->appendChild($email);
// add group element
$group = $doc->createElement('gContact:groupMembershipInfo');
$group->setAttribute('deleted' ,'false');
$group->setAttribute('href'
,'http://www.google.com/m8/feeds/groups/[email protected]
/base/343db1fa08c71f84');
$entry->appendChild($group);
// add org name element
$org = $doc->createElement('gd:organization');
$org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
$entry->appendChild($org);
$orgName = $doc->createElement('gd:orgName', $row['Company']);
$org->appendChild($orgName);
$orgTitle = $doc->createElement('gd:orgTitle', $row['JobTitle']);
$org->appendChild($orgTitle);
// add work phone elements
if($row['Phone']<>''){
$phoneNumber = $doc->createElement('gd:phoneNumber',
$row['Phone']);
$phoneNumber->setAttribute('rel'
,'http://schemas.google.com/g/2005#work');
$entry->appendChild($phoneNumber);
}
// add mobile phone elements
if($row['MobilePhone']<>''){
$phoneNumber = $doc->createElement('gd:phoneNumber',
$row['MobilePhone']);
$phoneNumber->setAttribute('rel'
,'http://schemas.google.com/g/2005#mobile');
$entry->appendChild($phoneNumber);
}
// insert entry
$entryResult = $gdata->insertEntry($doc->saveXML(),
'http://www.google.com/m8/feeds/contacts/default/full');
}
echo '<h2>Add Contact</h2>';
echo 'The ID of the new entry is: ' . $entryResult->id;
} catch (Exception $e) {
die('ERROR:' . $e->getMessage());
}
?>
On Thursday, June 30, 2011 10:15:39 AM UTC-4, Satish Bellapu wrote:
>
> In <gContact:groupMembershipInfo> you have to mention the <href> of the
> group, unless you provide that info, it won't add to any particular group,
> by default the server will add that contact to othercontacts.
>
> I don't think unless you have the group id, you can add the contacts to
> any group.
>
> --
> Regards,
> Satish Bellapu
>
> On Thu, Jun 30, 2011 at 7:08 PM, chrdesl <[email protected]> wrote:
>
>> Hi,
>>
>> i'm trying to *create a contact* and* add it to the system group:
>> mycontacts* using *api v3 (protocol)* without retrieving and updating
>> the contact*. Please help! Thx.*
>>
>> <atom:entry xmlns:atom='http://www.w3.org/2005/Atom'
>>
>> xmlns:gd='http://schemas.google.com/g/2005'>
>>
>> <atom:category scheme='http://schemas.google.com/g/2005#kind'
>>
>> term='http://schemas.google.com/contact/2008#contact' />
>>
>> <gd:name>
>> <gd:givenName>Elizabeth</gd:givenName>
>>
>> <gd:familyName>Bennet</gd:familyName>
>>
>> <gd:fullName>Elizabeth Bennet</gd:fullName>
>>
>> </gd:name>
>> <atom:content type='text'>Notes</atom:content>
>>
>> <gd:email rel='http://schemas.google.com/g/2005#work'
>>
>> primary='true'
>>
>> address='[email protected]' displayName='E. Bennet' />
>>
>> <gd:email rel='http://schemas.google.com/g/2005#home'
>>
>> address='[email protected]' />
>>
>> <gd:phoneNumber rel='http://schemas.google.com/g/2005#work'
>>
>> primary='true'>
>>
>> (206)555-1212
>> </gd:phoneNumber>
>> <gd:phoneNumber rel='http://schemas.google.com/g/2005#home'>
>>
>> (206)555-1213
>> </gd:phoneNumber>
>> <gd:im address='[email protected]'
>>
>> protocol='http://schemas.google.com/g/2005#GOOGLE_TALK'
>>
>> primary='true'
>>
>> rel='http://schemas.google.com/g/2005#home' />
>>
>> <gd:structuredPostalAddress
>> rel='http://schemas.google.com/g/2005#work'
>>
>> primary='true'>
>>
>> <gd:city>Mountain View</gd:city>
>>
>> <gd:street>1600 Amphitheatre Pkwy</gd:street>
>>
>> <gd:region>CA</gd:region>
>>
>> <gd:postcode>94043</gd:postcode>
>>
>> <gd:country>United States</gd:country>
>>
>> <gd:formattedAddress>
>> 1600 Amphitheatre Pkwy Mountain View
>> </gd:formattedAddress>
>>
>> </gd:structuredPostalAddress>*...... SOME METHODE TO ADD THIS CONTACT TO
>> THE SYSTEM GROUP: MY CONTACTS*
>> </atom:entry>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://code.google.com/apis/contacts/community/forum.html
>>
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html