如何从Google通讯录API中检索ID?

时间:2016-02-16 10:50:51

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

我正在尝试从Google Contacts API v3中检索ID。我能够在最后找到一个带有id的整个网址。

  

http://www.google.com/m8/feeds/contacts/mike%40xxxxxxx.com/base/xxxthisistheidxxxx

所以我要么以某种方式分割网址,要么我需要找到一种完全不同的方式来检索ID。

if (!empty($contacts['feed']['entry'])) {
    foreach($contacts['feed']['entry'] as $contact) {
        //retrieve Name and email address
        $return[] = array (
            'firstname'=> $contact['gd$name']['gd$givenName']['$t'],
            'lastname'=> $contact['gd$name']['gd$familyName']['$t'],
            'email' => $contact['gd$email'][0]['address'],
            'phoneNumber' => $contact['gd$phoneNumber'][0]['$t'],
            'city' => $contact['gd$structuredPostalAddress'][0]['gd$city']['$t'],
            'street' => $contact['gd$structuredPostalAddress'][0]['gd$street']['$t'],
            'country' => $contact['gd$structuredPostalAddress'][0]['gd$country']['$t'],
            'birthday' => $contact['gContact$birthday']['when'],
            'id' => $contact['id']['$t'],
        );
    }
}

2 个答案:

答案 0 :(得分:0)

您可以做的是在/&#39}上拆分网址,然后取结果的最后一个索引。

示例:

$url = "http://www.google.com/m8/feeds/contacts/mike%40xxxxxxx.com/base/xxxthisistheidxxxx";

$exploded = explode('/', $url);
echo end($exploded); //Echoes the last index.

答案 1 :(得分:0)

使用正则表达式:

preg_match("/[^\/]+$/", "http://www.google.com/m8/feeds/contacts/mike%40xxxxxxx.com/base/xxxthisistheidxxxx", $matches);
$last_word = $matches[0]; // test