如何从 Google 联系人 API 中检索 ID?

How can I retrieve an ID from Google Contacts API?

我正在尝试从 Google 联系人 API v3 中检索 ID。我能够在末尾检索到整个 url 和 id。

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

所以我要么以某种方式拆分了 url,要么我需要找到一种完全不同的检索 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'],
        );
    }
}

你可以做的是在 / 上拆分 url,然后取结果的最后一个索引。

示例:

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

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

使用正则表达式:

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