如何从Google OAuth2 PHP客户端获取用户国家和时区信息


How to get user country and timezone information from Google OAuth2 PHP Client

我正在使用PHP Google API客户端库使用OAuth2从Google帐户检索用户信息。然而,尽管谷歌的文档中有这样的说明,但我似乎无法访问用户的国家时区信息,即使令牌已成功返回,并且所有其他信息都可以从userinfo.profile范围中获得。

我在这里使用了在继承库中提供的示例代码,如果我在该文件的第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,但没有成功。它们似乎都提供了相同的结果。

我已经尽我所能确保会话/缓存和其他方面不是一个因素。甚至更新授权。什么都不管用。

任何人如果对如何通过Google API客户端库PHP正确检索这些信息有一些了解,都将是一个很好的帮助。

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

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

事实证明,这些信息根本不是谷歌提供的,他们的文档也已经过时了。