Facebook PHP-sdk 用户名
简单的问题:
我使用 php-sdk 在登录时获取用户图片。像这样:
$user = $facebook->getUser();
if ( $user )
{
try {
$user_profile = $facebook->api('/me'); .....
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> ....
但我也想获取用户名。我虽然我可以做这样的事情,只需添加:
<img src="https://graph.facebook.com/<?php echo $user; ?>/username">
当然这不起作用。我已经尝试了许多其他“名称”作为用户名,但我似乎找不到它!有人有一个简单的解决方案吗? :)
Simple question:
I've used php-sdk to get a hold of a users picture when logging in. Like this:
$user = $facebook->getUser();
if ( $user )
{
try {
$user_profile = $facebook->api('/me'); .....
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> ....
But I also want to get a hold of the username. I though I could do something like this, just add:
<img src="https://graph.facebook.com/<?php echo $user; ?>/username">
Of course this didn't work. I've tried many other "names" for a users name but I can't seem to find it! Someone got a simple solution? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您获得的用户名不会像这样使用,您也不应该将其放入 img 标签中。
使用图形浏览器获取有关可能结果的任何类型的信息。
对于用户名,获取“me”的响应并找到“username”的值。有关 Graph API 的各种探索,请参阅下文。
https:// Developers.facebook.com/tools/explorer?method=GET&path=me
Even if you are getting the username which you will not using like that, you should not be putting within an img tag..
Use the graph explorer for any kind of information on what are the possible results.
For the username get the response of 'me' and find the value of 'username'. See below for all kind of exploring on the Graph API..
https://developers.facebook.com/tools/explorer?method=GET&path=me
这无需访问令牌即可工作:
http://graph.facebook.com/{user_id}?fields=username
This will work without an access token:
http://graph.facebook.com/{user_id}?fields=username