简体   繁体   English

Google Contacts API获取所有联系方式(php)

[英]Google Contacts API get all contact details (php)

I'm using the Google Contacts API and I'm able to extract names and email addresses , phone number , image but I'd like to also get contact address , note and also how to extract email as work or home 我正在使用Google Contacts API,并且能够提取姓名和电子邮件地址,电话号码,图片,但我还希望获得联系地址,注释以及如何在工作或家庭中提取电子邮件

I'm using PHP and here's my code while authenticating: 我正在使用PHP,这是身份验证时的代码:

$document = new DOMDocument();
$document->loadXml($xmlresponse);
$xpath = new DOMXpath($document);
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$xpath->registerNamespace('gd', 'http://schemas.google.com/g/2005');

foreach ($xpath->evaluate('/atom:feed/atom:entry') as $entry) {
  $contact = [
    'name' => $xpath->evaluate('string(atom:title)', $entry),
    'image' => $xpath->evaluate('string(atom:link[@rel="http://schemas.google.com/contacts/2008/rel#photo"]/@href)', $entry),
    'emails' => [],
    'numbers' => [],
    'conatctaddress' => []
  ];
  foreach ($xpath->evaluate('gd:email', $entry) as $email) {
    $contact['emails'][] = $email->getAttribute('address');
  }
  foreach ($xpath->evaluate('gd:phoneNumber', $entry) as $number) {
    $contact['numbers'][] = trim($number->textContent);
  }

}

how to fetch contact address . 如何获取联系人地址。 they(google api) mentioned formattedAddress , structuredPostalAddress but dont how to fetch and also find if it is home or work 他们(谷歌api)提到formattedAddress,结构化PostalAddress,但不知道如何获取它,也不知道它是在家还是工作

EDIT 编辑

As mentioned in below answer im getting xml response but that response is not complete. 如下所述,我正在获取xml响应,但该响应尚未完成。 because contact details also contain birth date,anniversary,website details so this details are not fetch via 由于联系方式还包含生日,周年纪念日,网站详细信息,因此无法通过以下方式获取此详细信息

https://www.google.com/m8/feeds/contacts/default/full?&oauth_token=abcdferyyrfyfyt and also the remaining data im getting is as https://www.google.com/m8/feeds/contacts/default/full?&oauth_token=abcdferyyrfyfyt ,而其余​​的即时消息

<gd:organization rel='http://schemas.google.com/g/2005#other'><gd:orgName>comright</gd:orgName><gd:orgTitle>software developer</gd:orgTitle></gd:organization> so for this when i tried foreach loop as same for email im getting orgName and orgTitle in one variable <gd:organization rel='http://schemas.google.com/g/2005#other'><gd:orgName>comright</gd:orgName><gd:orgTitle>software developer</gd:orgTitle></gd:organization>因此当我尝试foreach loop就像电子邮件即时orgName ,在一个变量中获取orgNameorgTitle

You can Use the GET method to the url endpoint " https://www.google.com/m8/feeds/contacts/ {userEmail}/full" to retrieve the contacts from google. 您可以使用GET方法访问网址终结点“ https://www.google.com/m8/feeds/contacts/ {userEmail} / full”,以从Google检索联系人。 You can also go through the link .It will help you. 您也可以通过链接 。它将为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM