谷歌阿比让用户邮箱地址(Google Api get users Email Address)

2019-07-29 21:38发布

我使用的是谷歌阿比PHP客户端登录用户。我想获得用户的电子邮件地址。 我有下面的代码。

范围:

$client->setScopes('https://www.googleapis.com/auth/userinfo.profile');

码:

$request = new apiHttpRequest("https://www.googleapis.com/oauth2/v2/userinfo?alt=json");
$userinfo = $client->getIo()->authenticatedRequest($request);

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

这给我的只有以下细节

 Array ( [id] => 110084312800396764 [name] => Harsha MV [given_name] => Harsha M [family_name] => V [picture] => https://lh6.googleusercontent.com/-Xusc8lwgLIQ/AAAAAAAAAAI/AAAAAAAAAAA/sOthy23uJGk/photo.jpg [locale] => en ) 

Answer 1:

阵列中的设置范围做这项工作。

$this->client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));


Answer 2:

https://www.google.com/accounts/AuthSubRequest?next=http://www.example.com/index.php&scope=https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/analytics.readonly&secure=0&session=1 
or
https://www.google.com/accounts/AuthSubRequest?next=http://www.example.com/index.php&scope=email+https://www.googleapis.com/auth/analytics.readonly&secure=0&session=1

上述两种链接在PHP对我的作品



文章来源: Google Api get users Email Address