首页 文章

如何获取Google Apps for Work服务用户的姓名和电子邮件等基本 Profiles 信息

提问于
浏览
0

我正在尝试使用PHP客户端库获取Google Apps for Work用户的姓名和电子邮件等基本 Profiles 信息 . 根据this question我可以简单地使用people-> get函数https://www.googleapis.com/auth/plus.login范围 .

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

我还想提一下,Google Apps for Work的用户可能没有使用管理员激活的Google +服务,或者他们可能正在使用Google Plus服务不可用的旧版免费版 .

1 回答

  • 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;
    

相关问题