Google Api get users Email Address(Google Api 获取用户电子邮件地址)
本文介绍了Google Api 获取用户电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Google Api 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_r(json_decode($response, true), true) ."</pre>";
这只给我以下细节
<块引用>数组([id] =>110084312800396764[名称] =>哈沙MV[given_name] =>哈莎米[family_name] =>伏[图片] =>https://lh6.googleusercontent.com/-Xusc8lwgLIQ/AAAAAAAAAAI/AAAAAAAAAA/sOthy23uJGk/photo.jpg[语言环境] =>恩)
解决方案
在数组中设置范围即可.
$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'));
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 获取用户电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Google Api 获取用户电子邮件地址
基础教程推荐
猜你喜欢
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01