我刚收到一个 FB 应用程序项目,我正试图在它上线之前清理一些项目。
原程序员将用户ID号存储在数据库中,但不显示它或名称。我想在用户上传的图片下方显示用户名。
我的密码是 <?php echo $row['user_id']; ?>
, 有没有一种简单的方法可以将其转换为用户名?
最佳答案
使用名称字段从 API 调用 ID。
https://graph.facebook.com/user_id?fields=name
它应该返回
{
"name": "First Lastname",
"id": "user_id"
}
保存到一个变量然后提取
$user['name'];
更多信息http://developers.facebook.com/docs/reference/api/user/
没有 SDK/access token 的例子,
$response = file_get_contents("https://graph.facebook.com/4?fields=name");
$user = json_decode($reponse,true);
echo $user['name'];
应该打印,
'Mark Zuckerberg'
关于 Facebook 应用 : Getting a user's name from ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10917630/