English 中文(简体)
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 Google 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.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签