The Little Guy Posted April 1, 2011 Share Posted April 1, 2011 I am writing a google contact API to get users contacts, I get everything back except for the email address of the contact. Anyone know how to get the contacts email address? <?php class gdata{ private $headers; private $googleAuth = 'http://www.google.com/m8/feeds'; private $google = 'http://www.google.com/m8/feeds/contacts/default/full'; public $token; public function headers(){ $this->headers['GData-Version'] = '3.0'; $this->headers['Authorization'] = "AuthSub token=\"$this->token\""; $this->headers['Content-Type'] = "application/x-www-form-urlencoded"; $this->headers['Host'] = "www.google.com"; $this->headers['User-Agent'] = "php/".phpversion(); $this->headers['Accept'] = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; $this->headers['Connection'] = "keep-alive"; } public function request_contacts($email){ $ch = curl_init(); $headers = array(); foreach($this->headers as $k => $v){ $headers[] = "$k: $v"; } $url = preg_replace("/\[email_address\]/", $email, $this->google); echo $url; curl_setopt($ch, CURLOPT_URL, $this->google); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $opt = curl_exec($ch); $xml = simplexml_load_string($opt); header("Content-type: text/plain"); foreach($xml->entry as $user){ //echo $user['link'] } print_r($xml->entry[5]); } public function auth(){ $next = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?a=getContacts'; header("Location: https://www.google.com/accounts/AuthSubRequest?next=".urlencode($next)."&scope=".urlencode($this->googleAuth)."&session=1&secure=0"); } } $gAPI = new gdata(); if($_GET['a'] == 'getContacts'){ $gAPI->token = $_GET['token']; $gAPI->headers(); $gAPI->request_contacts('untuned20@gmail.com'); }else{ $gAPI->auth(); } ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 1, 2011 Author Share Posted April 1, 2011 Never mind, simplexml_load_string() does not grab everything. I just did a regular expression to grab them. Quote Link to comment Share on other sites More sharing options...
The Letter E Posted April 1, 2011 Share Posted April 1, 2011 I've had luck when working with the googel apis using this function: xml_parse_into_struct(); Check it out on php.net , might be easier than a regex. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 1, 2011 Author Share Posted April 1, 2011 OK, I choose to do the json method. how do I access this? stdClass Object ( [gd$email] => Array ) stdClass Object ( [gd$etag] => "R3k-ejVSLyt7I2A9Wx9aFkUMRAM." [id] => stdClass Object ( [$t] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/base/0 ) [updated] => stdClass Object ( [$t] => 2011-03-09T15:59:36.752Z ) [app$edited] => stdClass Object ( [xmlns$app] => http://www.w3.org/2007/app [$t] => 2011-03-09T15:59:36.752Z ) [category] => Array ( [0] => stdClass Object ( [scheme] => http://schemas.google.com/g/2005#kind [term] => http://schemas.google.com/contact/2008#contact ) ) [title] => stdClass Object ( [$t] => ) [link] => Array ( [0] => stdClass Object ( [rel] => http://schemas.google.com/contacts/2008/rel#photo [type] => image/* [href] => http://www.google.com/m8/feeds/photos/media/untuned20%40gmail.com/0 ) [1] => stdClass Object ( [rel] => self [type] => application/atom+xml [href] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/full/0 ) [2] => stdClass Object ( [rel] => edit [type] => application/atom+xml [href] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/full/0 ) ) [gd$email] => Array ( [0] => stdClass Object ( [rel] => http://schemas.google.com/g/2005#other [address] => untuned20@gmail.com [primary] => true ) ) ) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 1, 2011 Author Share Posted April 1, 2011 nvm again. All solved: json_decode($inputString, true); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.