我目前正在收到电子邮件和姓名,如下所示:
function tratar_gmail($accesstoken){
$max_results = 3000;
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$accesstoken;
//echo $url;
$xmlresponse = curl_file_get_contents($url);
if((strlen(stristr($xmlresponse,'Authorization required'))>0) && (strlen(stristr($xmlresponse,'Error '))>0))
{
echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
exit();
}
$xml = new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
$return;
foreach ($result as $title) {
$parts = explode('@', $title->attributes()->address);
$pos = count($return);
$return[$pos]['email'] = $title->attributes()->address;
$return[$pos]['name'] = strip_tags($parts[0]);
}
$title
转储的地方:
object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(3) { ["rel"]=> string(38) "http://schemas.google.com/g/2005#other" ["address"]=> string(18) "xxxxxxx@wanadoo.es" ["primary"]=> string(4) "true" } }
但是获取一些图片会很棒,至少对于Gmail联系人来说,有没有办法?
类似的东西:
$return[$pos]['email'] = $title->attributes()->address;
$return[$pos]['name'] = strip_tags($parts[0]);
if (preg_match('/^gmail.com/', $return[$pos]['emal']) {
$return[$pos]['pic'] = magic_goes_here()
}
答案 0 :(得分:0)
照片链接可在联系人条目中找到:
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:gContact='http://schemas.google.com/contact/2008'
xmlns:gd='http://schemas.google.com/g/2005'
gd:etag='{contactEtag}'>
<id>
http://www.google.com/m8/feeds/contacts/{userEmail}/base/{contactId}
</id>
...
<link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
href='https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId}'
gd:etag='{photoEtag}'/>
如果没有照片,则link
元素将不具有属性gd:etag
。
要检索每个联系人的图片,请获取该网址:
https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactId}