Hello all, I've been trying to create a simple google contact with PHP, with 
name, address, email, phone number, and organization name. I've searched 
tirelessly through this forum and throughout the internet and have not found 
a php script that works for this that is up to date as of 9/2011. I'm 
thinking maybe the scripts I found used to work but don't work anymore? Will 
someone please advise me on a php script that will add a google contact via 
php?


The one script I found that came close only adds the phone number and 
comments, nothing else:

 $extension = new Zend_Gdata_App_Extension_Element('email', null, ' 
http://schemas.google.com/g/2005'); 
 $attributes['address'] = array('namespaceUri'=>null,'name'=>'address', 
'value' => $emailaddy); 
 $attributes['rel'] = array('namespaceUri'=>null,'name'=>'rel', 'value' => 
' 
http://schemas.google.com/g/2005#home'); 
 $attributes['primary'] = array('namespaceUri'=>null,'name'=>'primary', 
'value' => 'true'); 
 $extension->setExtensionAttributes($attributes); 
 $entry = $gdata->newEntry(); 
 $entry->title = $gdata->newTitle($name); 
 $entry->setExtensionElements(array($extension)); 
    $extensionElements = $entry->getExtensionElements(); 
    $extension2 = new Zend_Gdata_App_Extension_Element('postalAddress', 
null, 'http://schemas.google.com/g/2005'); 
    $attributes2 = array(); 
    $extension2->setText($contactAddress); 
    $attributes2['rel'] = array('namespaceUri'=>null,'name'=>'rel', 'value' 
=> 'http://schemas.google.com/g/2005#home'); 
    $attributes2['primary'] = array('namespaceUri'=>null,'name'=>'primary', 
'value' => 'true'); 
    $extension2->setExtensionAttributes($attributes2); 
    array_push($extensionElements, $extension2); 
    $entry->setExtensionElements($extensionElements); 
    $extensionElements = $entry->getExtensionElements(); 
    $extension3 = new Zend_Gdata_App_Extension_Element('phoneNumber', null, 
'http://schemas.google.com/g/2005'); 
    $attributes3 = array(); 
    $extension3->setText($phone); 
    $attributes3['rel'] = array('namespaceUri'=>null,'name'=>'rel', 'value' 
=> 'http://schemas.google.com/g/2005#home'); 
    $attributes3['primary'] = array('namespaceUri'=>null,'name'=>'primary', 
'value' => 'true'); 
    $extension3->setExtensionAttributes($attributes3); 
    array_push($extensionElements, $extension3); 
    $entry->setExtensionElements($extensionElements); 
 $content = $gdata->newContent($comments); 
 $content->setType('text'); 
 $entry->content = $content; 
 $entryResult = $gdata->insertEntry($entry,$mystream); 


###############################################################################


This script I found only seems to add the name, email, and company name, 
nothing else:

$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'); 
  $doc->appendChild($entry); 

  // add name element 
  $name = $doc->createElement('gd:name'); 
  $entry->appendChild($name); 
  $name1="Jason Mac"; 
  $fullName = $doc->createElement('gd:fullName', $name1); 
  $name->appendChild($fullName); 

  // add email element 
  $email = $doc->createElement('gd:email'); 
  $email1=$emailAddress; 
   $email->setAttribute('address' ,$email1); 
  $email->setAttribute('rel' ,'http://schemas.google.com/g/2005#home'); 
  $entry->appendChild($email); 

  // add org name element 
  $org = $doc->createElement('gd:organization'); 
  $org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work'); 
  $entry->appendChild($org); 
  $orgNamer="my Org";
  $orgName = $doc->createElement('gd:orgName', $orgNamer); 
  $org->appendChild($orgName); 


  // add org name element 
  $Phone = $doc->createElement('gd:Phone'); 
  $Phone->setAttribute('rel' ,'http://schemas.google.com/g/2005#work'); 
  $entry->appendChild($Phone); 
  $phone1="7777777777"; 
   $PhoneName = $doc->createElement('gd:PhoneName', $phone1); 
  $Phone->appendChild($PhoneName); 

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



######################################################################

Any suggestions on how to add the name, address, phone, email, and 
organization name for a contact would be greatly appreciated! (and if you 
know how to add multiple email addresses / multiple phone numbers that's a 
big bonus)


Thanks, Jason


-- 
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

Reply via email to