Google API-获取联系人邮件

Arkadiusz G.

我想通过朋友的电子邮件获得完整的联系人列表。我可以获取联系人列表,但没有电子邮件。

是我的代码:

require_once APPPATH . 'vendor/google/src/Google_Client.php';
require_once APPPATH . 'vendor/google/src/contrib/Google_Oauth2Service.php';
$client = new Google_Client();

$client->setApplicationName("PHP Google Test");
$client->setClientId('xxx');
$client->setClientSecret('xxx');
$client->setRedirectUri('http://www.domain.xx/admin/others/google?test');
$client->setScopes("http://www.google.com/m8/feeds/");

$oauth2 = new Google_Oauth2Service($client);

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    $redirect          = 'http://www.domain.xx/admin/others/google';
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['token']);
    $client->revokeToken();
}
if ($client->getAccessToken()) {
    $req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
    $val = $client->getIo()->authenticatedRequest($req);
    $response = json_encode(simplexml_load_string($val->getResponseBody()));
    print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";
    $_SESSION['token'] = $client->getAccessToken();
} else {
    $auth = $client->createAuthUrl();
}

$auth = $client->createAuthUrl();

echo '<a href="' . $auth . '" target="_blank">' . $auth . '</a>';

我如何从联系人列表中获取电子邮件?

Arkadiusz G.

我有解决办法:

码:

$response = json_encode(simplexml_load_string($val->getResponseBody()));
print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";

改成:

$xml = simplexml_load_string($val->getResponseBody());
            $xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');         

            $output_array = array();
            foreach ($xml->entry as $entry) {
              foreach ($entry->xpath('gd:email') as $email) {
                $output_array[] = array((string)$entry->title, (string)$email->attributes()->address);
              }
            }
           print_r($output_array);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从Google Api获取联系人

Google API /获取目录联系人

使用 Google 联系人 api 获取组明智的联系人

从节点中的Google API获取联系人

Google People API / 其他联系人 - 如何获取其他联系人的照片?

Google Contacts API 中经常联系的联系人

如何使用Google People API在Android中获取其他联系人

从Google Contacts API 3.0版获取所有联系人

我如何使用People API获取Google联系人组的成员列表?

从谷歌人 api 获取联系人

使用 Google People API 未显示 Google 联系人

使用客户端库描述 google 联系人/gmail 联系人的 api

如何通过Google Contacts API创建新联系人?

Google Contacts API检索每个联系人的组名

如何使用Google CardDAV API插入新联系人?

Google 日历 API 要求“管理您的联系人”权限?

Google Script - 如何从完整的联系人姓名中获取电子邮件地址

如何使用 Microsoft 的 EWS API 2.0 获取联系人的电子邮件地址?

使用Google Apps脚本将创建的联系人按人api添加到群组

使用 Google Apps 脚本使用 People API 更新 Google 联系人照片

在 Google Apps Script 中使用 Google People API 删除联系人返回 404 错误

SurveyMonkey API-获取所有联系人

如何从Azure广告图API获取联系人

Google通讯录API-删除联系人(400错误)

Google联系人API无法打开流:HTTP请求失败!HTTP / 1.0 403 Forbidden'

检索有关使用Google People API(Java)的联系人的信息

如何使用People API和Node.js创建Google联系人

无法在PHP中使用Google Contacts API V3创建联系人/组

google-people api是否提供回调来确定联系人列表何时更改?