开发者

Using Google's Contacts API's, how can I get the user's name and gmail address?

I know how to get the entire contacts list using Google Contacts API (I get a session token and use Goog开发者_如何学JAVAle's Zend package for PHP).

But how can I get the person's name and email address? Currently, the Contacts API just seems to give all of the contacts. I'm not sure how to distinguish which email and name out of that list corresponds to the user's account.

Is there an easy way to get the user's full name and email address?

Any help would be useful. Thanks!


yes goto http://code.google.com/apis/contacts/docs/3.0/reference.html#ContactsFeed and see the "Contacts feed" they say to use the Default, it worked for me after using the default - lower case only.

request

http://www.google.com/m8/feeds/contacts/default/full

will give you the user's details.

http://www.google.com/m8/feeds/contacts/bla@gmail.com/full

will give you a contact info (if bla@gmail.com) is a contact.


If you ask for the "default" contact (i.e., me), you get what you need. Mind that you need to write default with a lowercase d and not as written in the documentation.


THe xml returned for the default contact list will have the user's name and email within the "author" element. I don't know PHP, but the code might look something like this...

  email = xml["author"].first["email"].first
  name = xml["author"].first["name"].first


You can obtain this information by querying :

"https://www.google.com/m8/feeds/contacts/default/full?oauth_token=YourToken123"

and parsing your XML (SimpleXML example):

$user_email = $xmlResult->id;
$user_name  = $xmlResult->author->name;

$xmlResult->author->name will give you the whole name as the user has configured it, so it's not certain that you will get in the "FirstName Lastname" format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜