如何从谷歌通讯录 API 检索 ID



我正在尝试从Google Contacts API v3中检索ID。我能够检索末尾带有 id 的整个 url。

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 = "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

相关内容

  • 没有找到相关文章

最新更新