【问题标题】:Facebook API: Find User name from User IDFacebook API:从用户 ID 中查找用户名
【发布时间】:2015-03-13 13:23:43
【问题描述】:

我有 facebook 用户 id,如何从这个 id 获取用户名?

我试过了

    $response = file_get_contents('https://graph.facebook.com/' . $userId . '?fields=name');
    $user = json_decode($reponse, true);
    print_r($user['name']);
    exit;

但它有一个错误 file_get_contents(https://graph.facebook.com/"id_of_user"?fields=name):打开流失败:HTTP 请求失败! HTTP/1.1 400 错误请求

有没有其他方法可以从用户id中获取用户名??

[编辑]

我获取的用户 ID 是为我的应用生成的用户 ID

【问题讨论】:

    标签: php facebook facebook-apps


    【解决方案1】:

    您无法再获得用户名,但我假设您仍然想要用户的真实姓名 - 这仍然是可能的。

    我的猜测是您的服务器阻止了请求,您应该联系您的提供商。另外,最好使用CURL 而不是file_get_contents

    顺便说一句,如果那是一个 App Scoped ID,则您需要为该调用使用访问令牌 - 这很可能是这种情况,因为无法再在 App 中获取真实/全局用户 ID。有关访问令牌的更多信息:

    如果您不知道什么是 App Scoped ID,请查看更改日志:https://developers.facebook.com/docs/apps/changelog

    【讨论】:

    • 我得到的响应是 { "error": { "message": "Unsupported get request. Please read the Graph API documentation at developers.facebook.com/docs/graph-api", "type": "GraphMethodException", "code ": 100 } }
    • 那你的电话错了。确切的电话是什么?它是全局 id 还是应用范围的 ID?您在使用访问令牌吗?哪一个?用户令牌?应用令牌?
    • 这是 file_get_contents('graph.facebook.com' . $userId . '?fields=name');
    • 正如我所说,您需要使用访问令牌,并且需要使用应用范围的 id
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    相关资源
    最近更新 更多