【问题标题】:Google Contacts API get all contact details (php)Google Contacts API 获取所有联系方式 (php)
【发布时间】:2016-07-26 06:43:24
【问题描述】:

我正在使用 Google Contacts API,我能够提取姓名和电子邮件地址、电话号码、图片,但我还想获取联系地址、备注以及如何将电子邮件提取为工作或家庭

我正在使用 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);
  }

}

如何获取联系地址。他们(google api)提到了 formattedAddress ,structuredPostalAddress 但不知道如何获取以及查找它是在家还是在工作

编辑

正如下面的答案中提到的,我得到了 xml 响应,但该响应不完整。因为联系方式还包含出生日期、周年纪念日、网站详细信息,因此无法通过

获取此详细信息

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> 所以为此,当我尝试foreach loop 时,我将orgNameorgTitle 放在一个变量中

【问题讨论】:

    标签: php google-api google-contacts-api


    【解决方案1】:

    您可以使用 GET 方法到 url 端点“https://www.google.com/m8/feeds/contacts/{userEmail}/full”从 google 检索联系人。你也可以通过link.它会帮助你。

    【讨论】:

    • 使用上面的 url 作为https://www.google.com/m8/feeds/contacts/default/full?&oauth_token=1234567894 我得到 xml 响应,但它没有获取完整的响应。例如我无法获取
    猜你喜欢
    • 2014-08-15
    • 2016-01-19
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多