Need Help on OAuthException Code 2500

时光怂恿深爱的人放手 提交于 2019-11-28 08:40:48

Error 2500 means you have no access token or an app access token but are trying to access /me/ - 'me' is a placeholder for 'current user or page ID' so won't be valid without an access token for a user or page.

To access the user's list of likes you'll also need the user_likes Permission when authorising them

The most likely causes i've seen for apps not being able to exchange the code for an access token are:

  1. The redirect_uri you used is to a folder or server root and is missing a trailing slash (i.e it's http://www.example.com instead of http://www.example.com/)
  2. The redirect_uri you used in the first call to the auth dialog wasn't precisely the same as the redirect_uri you used in the call to exchagne the code for an access_token

If your auth flow is broken for some other reason and you can't figure it out from the SDK examples or the Authentication documentation, this could take a while for someone to talk you through because you may be missing some background knowledge necessary to understand their answers

lezoconnor

For me, I was trying to get an auth token with php and found out that the 2500 error was due to an issue with file_get_contents not returning anything. I could access the URL in my browser, but not by using file_get_contents. I fixed it by using CURL instead as described here: https://stackoverflow.com/a/6325313.

The result was that I used the code from https://developers.facebook.com/docs/authentication/server-side/ and replaced the line:

$response = file_get_contents($token_url);

with

$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

It therefore became:

   $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id . "&redirect_uri=" . urlencode($redirect_url)
        . "&client_secret=" . $app_secret
        . "&code=" . $code;

    /* Facebook say to use this, but file_get_contents isn't working!
    $response = file_get_contents($token_url,null, $val);
    */

    // Use this as an alternative
    $ch = curl_init($token_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);

    // From https://developers.facebook.com/docs/authentication/server-side/
    $params = null;
    parse_str($response, $params);
    $access_token = $params['access_token'];

try This code

$code = $_REQUEST["code"];
  if(empty($code)) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&redirect_uri=" . urlencode($my_url) ;
    echo("<script>top.location.href='" . $dialog_url . "'</script>");
  }

  $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url) 
    . "&client_secret=" . $app_secret 
    . "&code=" . $code;
    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);
    $access_token = $params['access_token'];

PS:user email address is not a public info & you need user_email permission for it

I have solved my problem thanks to https://developers.facebook.com/blog/post/534/

I just copied the sample and pasted into my script. It fully fits. It is kind of hybrid usage of PHP and Javascript.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!