【问题标题】:How to get user country and timezone information from Google OAuth2 PHP Client如何从 Google OAuth2 PHP 客户端获取用户国家和时区信息
【发布时间】: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.loginhttps://www.googleapis.com/auth/plus.mehttps://www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/userinfo.profilehttps://www.googleapis.com/auth/userinfo,但没有运气。它们似乎都提供了相同的结果。

我已尽可能确保会话/缓存和其他方面不是一个因素。甚至更新已采取的身份验证。没有任何效果。

任何对如何通过适用于 PHP 的 Google API 客户端库正确检索此信息有所了解的人都会有很大帮助。

【问题讨论】:

    标签: php google-api google-api-php-client


    【解决方案1】:

    事实证明,这些信息根本不是由 Google 提供的,而且他们的文档已经过时了。

    【讨论】:

    • 同意。文档非常分散,几乎不可能找到您要查找的内容。更不用说它的记录有多差了。像谷歌这样的巨人怎么会不记录他们的 API?这只会伤害他们,因为开发人员不愿意使用他们的 API。
    【解决方案2】:

    Google Calendar API -> CalendarList -> list 方法返回我使用的用户日历时区。我同意,时区应该是 plus->people->get 的一部分。

    文档位于: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list

    【讨论】:

      猜你喜欢
      • 2011-02-17
      • 2011-12-06
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      相关资源
      最近更新 更多