2015-04-16 31 views
0

我正在尝试使用PHP客户端库获取Google Apps for Work用户的姓名和电子邮件等基本个人资料信息。根据this question我可以做到这一点,只需使用people->获得与https://www.googleapis.com/auth/plus.login范围的功能。如何获取Google Apps for Work用户的姓名和电子邮件等基本个人资料信息

我试过这个,这个工作正常与@ gmail.com帐户,但与谷歌Apps for Work users.I我也尝试使用plus_domains服务,但结果相同。我设法使用Gmail的范围获得电子邮件地址,但仍然没有获得用户名的运气。

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

+0

是否按照[这个问题]的意思(http://stackoverflow.com/questions/29616741 /它,想成为右服务使用的功能于PHP客户端库换谷歌对获得 - 巴斯酒)? – malcanso

回答

0

我已经使用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; 
相关问题