Zend Gdata PHP api for Google Contacts Data

  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

I need a gmail personal contact manager solution. We recently went to google apps premier and there's no way for our few people to share their personal contacts aside from sending a vcard. Some also need collaboration abilities and I thought the best option would be to deploy a small php program that allowed access to just the contacts of another user. I'm using the zend framework and overall I'm doing fine building an add, edit, and delete pages but I'm having difficulty mapping the atom feed. I've searched google and zend and nowhere do they give me a complete listing of the elements and attributes. Google gives one crappy example of a feed with one contact. I thought I could echo my $feed variable after I do a Zend_Query but that's not printing to the screen or source. I need to see an example of a full feed so I know the names of the nodes I'm dealing with so I can parse correctly. Am I right or am I missing something here?

The Zend Framework does something like this:

Code: [ Select ]

$client = Zend_Gdata_ClientLogin::getHttpClient(
    $user, $pass, 'cp');
   $gdata = new Zend_Gdata($client);
   $gdata->setMajorProtocolVersion(3);
   
   // perform query and get feed of all results
   $query = new Zend_Gdata_Query(
    'http://www.google.com/m8/feeds/contacts/default/full');
   $query->maxResults = 0;
   $query->setParam('orderby', 'lastmodified');
   $query->setParam('sortorder', 'descending');
   $feed = $gdata->getFeed($query);
foreach($feed as $entry){
    $obj = new stdClass;
    $obj->edit = $entry->getEditLink()->href;
    $xml = simplexml_load_string($entry->getXML());
    $obj->name = (string) $entry->title;
    $obj->orgName = (string) $xml->organization->orgName;
    $obj->orgTitle = (string) $xml->organization->orgTitle;
    $obj->instantmessenger = (string) $xml->im;

    foreach ($xml->email as $e) {
     $obj->emailAddress[] = (string) $e['address'];
    }
    
    foreach ($xml->phoneNumber as $p) {
     $obj->phoneNumber[] = (string) $p;
    }
    foreach ($xml->website as $w) {
     $obj->website[] = (string) $w['href'];
    }
    
    $results[] = $obj; 
   }
     
     print_r($results);
  1. $client = Zend_Gdata_ClientLogin::getHttpClient(
  2.     $user, $pass, 'cp');
  3.    $gdata = new Zend_Gdata($client);
  4.    $gdata->setMajorProtocolVersion(3);
  5.    
  6.    // perform query and get feed of all results
  7.    $query = new Zend_Gdata_Query(
  8.     'http://www.google.com/m8/feeds/contacts/default/full');
  9.    $query->maxResults = 0;
  10.    $query->setParam('orderby', 'lastmodified');
  11.    $query->setParam('sortorder', 'descending');
  12.    $feed = $gdata->getFeed($query);
  13. foreach($feed as $entry){
  14.     $obj = new stdClass;
  15.     $obj->edit = $entry->getEditLink()->href;
  16.     $xml = simplexml_load_string($entry->getXML());
  17.     $obj->name = (string) $entry->title;
  18.     $obj->orgName = (string) $xml->organization->orgName;
  19.     $obj->orgTitle = (string) $xml->organization->orgTitle;
  20.     $obj->instantmessenger = (string) $xml->im;
  21.     foreach ($xml->email as $e) {
  22.      $obj->emailAddress[] = (string) $e['address'];
  23.     }
  24.     
  25.     foreach ($xml->phoneNumber as $p) {
  26.      $obj->phoneNumber[] = (string) $p;
  27.     }
  28.     foreach ($xml->website as $w) {
  29.      $obj->website[] = (string) $w['href'];
  30.     }
  31.     
  32.     $results[] = $obj; 
  33.    }
  34.      
  35.      print_r($results);


Here they simply rebuild their own results array with the $obj. I don't know how I'm suppose to know all the $obj variables I have. I guessed $obj->instantmessenger = (string) $xml->im; ... it didn't throw an error so I'm thinking I got that one right. One I changed and it threw me an error and said it didn't exist. However, one of my contacts has an im field filled out and it didn't show up. So, I'm posting.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 70 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.