【问题标题】:How to get basic profile information like name and email of users of Google Apps for Work services如何获取 Google Apps for Work 服务用户的姓名和电子邮件等基本个人资料信息
【发布时间】:2015-04-16 17:53:31
【问题描述】:

我正在尝试使用 PHP 客户端库获取 Google Apps for Work 用户的姓名和电子邮件等基本个人资料信息。根据this question,我可以简单地使用带有https://www.googleapis.com/auth/plus.login 范围的people->get 函数来做到这一点。

我试过这个,这适用于@gmail.com 帐户,但不适用于 Google Apps for Work 用户。我也尝试使用 plus_domains 服务,但结果相同。我设法使用 gmail 范围获取电子邮件地址,但仍然无法获取用户名。

我还想提一下,Google Apps for Work 的用户可能没有由管理员激活 Google plus 服务,或者他们可能使用的是旧版免费版本,而 Google plus 服务不可用。

【问题讨论】:

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


【解决方案1】:

我已经使用 Google Apps for Education 运行它,而不使用 Google Plus API,只使用 OAuth2 API。 这些是我添加的范围:

$client->addScope(Google_Service_Oauth2::USERINFO_PROFILE);
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);

那么你可以这样使用它:

$oauthService = new Google_Service_Oauth2($client);
$userInfo = $oauthService->userinfo_v2_me->get();
echo "User info:<br>Name: ".$userInfo->name
  ."<br>givenName: ".$userInfo->givenName
  ."<br>familyName: ".$userInfo->familyName
  ."<br>email: ".$userInfo->email;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2021-01-16
    相关资源
    最近更新 更多