【问题标题】:Trying to access facebook friends on server side with given access token. OAuthException code => 2500 Error尝试使用给定的访问令牌访问服务器端的 facebook 朋友。 OAuthException 代码 => 2500 错误
【发布时间】:2013-05-12 16:23:51
【问题描述】:

我正在尝试使用访问令牌(客户端代码发送给我)在服务器端检索用户的朋友列表。我正在使用 file_get_contents 来检索朋友列表,并使用 RecursiveIteratorIterator 将其显示在屏幕上。有人可以指导我如何解决错误吗?

$context = stream_context_create(array(
    'http' => array(
    'ignore_errors'=>true,
    'method'=>'POST'

)
));

$response = json_decode(file_get_contents("https://graph.facebook.com/me/friendsaccess_token=".$token, false, $context));


    $jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator($response, RecursiveIteratorIterator::SELF_FIRST));

    foreach ($jsonIterator as $key => $val) {
        if(is_array($val)) {
            echo "$key:\n";
        } else {
            echo "$key => $val\n";
    }

错误:

message => Unknown path components:/friendsaccess_token=<Access_Token>
type => OAuthException
code => 2500

【问题讨论】:

  • 通过有问题吗?请标记答案并关闭此问题。

标签: php facebook-graph-api facebook-access-token


【解决方案1】:

您需要在查询字符串中传递access_token。所以在friends之后的URL请求中打上问号(?)。

$response = json_decode(file_get_contents("https://graph.facebook.com/me/friends?access_token=".$token, false, $context));

【讨论】:

  • 这从错误消息中很明显,Unknown path components:/friendsaccess_token=&lt;Access_Token&gt; 你得到了
  • 感谢您的回复。我现在收到“消息 => (#100) 类型 => OAuthException 代码 => 100”。你能帮我解决一下吗?
  • 尝试将方法从 POST 更改为 GET
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多