Google Api获取用户的电子邮件地址 [英] Google Api get users Email Address

查看:104
本文介绍了Google Api获取用户的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Api PHP客户端登录用户。我想获取用户电子邮件地址。

I am using the Google Api PHP client to Log the user in. I want to get the Users Email address. I have the following code.

范围:

Scope:

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

代码:

Code:

$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>";

这只给我以下详细信息:

This give me only the following details


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



推荐答案

在数组中设置作用域执行作业。

Setting the scope in an array does the job.

$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'));

这篇关于Google Api获取用户的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆