【发布时间】:2013-08-21 23:08:48
【问题描述】:
我正在使用PHP Google API Client Library 使用 OAuth2 从 Google 帐户检索用户信息。然而,尽管Google's documentation states,我似乎无法访问用户的国家/地区或时区信息,即使令牌成功返回并且所有其他信息都可以从userinfo.profile 范围。
我使用了继承人库 here 中提供的示例代码,如果我在该文件的第 49 行 var_dump($user),我会得到以下输出(出于隐私考虑而编辑):
array(10) {
["id"]=>
string(21) "123" /* Redacted */
["email"]=>
string(13) "XXX@gmail.com" /* Redacted */
["verified_email"]=>
bool(true)
["name"]=>
string(14) "Sherif Ramadan"
["given_name"]=>
string(6) "Sherif"
["family_name"]=>
string(7) "Ramadan"
["link"]=>
string(27) "https://plus.google.com/XXX" /* Redacted */
["picture"]=>
string(0) "https://lh3.googleusercontent.com/-XXX-Zs/AAAAAAAAAA/AAAAAAAAA/cmBwzMLdYqM/photo.jpg" /* Redacted */
["gender"]=>
string(4) "male"
["locale"]=>
string(2) "en"
}
如您所见,没有可用的时区或国家/地区信息。我也尝试了各种范围,例如https://www.googleapis.com/auth/plus.login、https://www.googleapis.com/auth/plus.me、https://www.googleapis.com/auth/userinfo.email、https://www.googleapis.com/auth/userinfo.profile 和https://www.googleapis.com/auth/userinfo,但没有运气。它们似乎都提供了相同的结果。
我已尽可能确保会话/缓存和其他方面不是一个因素。甚至更新已采取的身份验证。没有任何效果。
任何对如何通过适用于 PHP 的 Google API 客户端库正确检索此信息有所了解的人都会有很大帮助。
【问题讨论】:
标签: php google-api google-api-php-client