doujiexin1136 2015-09-27 00:35
浏览 59
已采纳

如何从谷歌身份工具包获取用户的图像

The google identity toolkit PHP Quick Start app provides the following block of code that displays some information about the user once they have successfully logged in.

<?php if ($gitkitUser) { ?>
    Welcome back!<br><br>
    Email: <?= $gitkitUser->getEmail() ?><br>
    Id: <?= $gitkitUser->getUserId() ?><br>
    Name: <?= $gitkitUser->getDisplayName() ?><br>
    Identity provider: <?= $gitkitUser->getProviderId() ?><br>
<?php } else { ?>
    You are not logged in yet.
<?php } ?>

The output on the page looks like this:

Email: someuser@hotmail.com 
Id: 123
Name: Bob User
Identity provider: facebook.com

I would like to display the user's avatar/photo as well but can not seem to sort out how to do this. I've tried $gitkitUser->getPhotoUrl(); but that seems to return nothing and I can't find any good documentation.

If I print_r the $gitkitUser object I can see there is indeed a photoUrl and the URL is correct but it's set to private and I can't seem to access it:

Gitkit_Account Object(
     [localId: Gitkit_Account: private] => 123
     [email: Gitkit_Account: private] => someuser@hotmail.com
     [providerId: Gitkit_Account: private] => facebook.com
     [providerInfo: Gitkit_Account: private] => Array([0] => Array(
        [providerId] => facebook.com
        [displayName] => Bob User
        [photoUrl] => https: //scontent.xx.fbcdn.net/..... 
        [federatedId] => http://facebook.com/123 ) 
     ) 
     [displayName:Gitkit_Account:private] => Bob User 
     [photoUrl:Gitkit_Account:private] => 
     [emailVerified:Gitkit_Account:private] => 
     [passwordHash:Gitkit_Account:private] => 
     [salt:Gitkit_Account:private] => 
)

Any ideas as to how I can get access to the user's image to display on the page?

  • 写回答

1条回答 默认 最新

  • douza1373 2015-09-27 03:55
    关注

    Yes, I too noticed that $gitkitUser->getPhotoUrl() retrieves an empty value. I guess the photoUrl doesn't get populated automatically like the others. They recently added a getProviderInfo method that you can use like this to get the photo URL from the first federated ID:

    $provider_info = $gitkitUser->getProviderInfo();
    $photo_url = $provider_info[0]['photoUrl'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址