doujiang7258 2015-04-16 17:53
浏览 44
已采纳

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

I am trying to get basic profile information like name and email of users of Google Apps for Work using PHP client library . According to this question I can do that simply using people->get function with https://www.googleapis.com/auth/plus.login scope.

I tried this and this works fine with @gmail.com accounts, but not with Google Apps for Work users.I also tried using plus_domains service but same results. I managed to get email address using gmail scope but still no luck with getting user's name.

I would like to also mention that users of Google Apps for Work might not have Google plus service activated by admin or they could be using legacy free edition, where Google plus service is not available.

  • 写回答

1条回答 默认 最新

  • douhao8456 2015-11-09 09:19
    关注

    I've got it working using Google Apps for Education, without using the Google Plus API, just the OAuth2 API. These are the scopes I've added:

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

    Then you can use it this way:

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测