Facebook graph API - OAuth Token

后端 未结 11 1834
小鲜肉
小鲜肉 2021-01-30 09:16

I\'m trying to retrieve data using the new graph API, however the token I\'m retriving from OAuth doesn\'t appear to be working.

The call I\'m making is as follows;

相关标签:
11条回答
  • 2021-01-30 09:46

    Please note that

    'type' => 'client_cred',

    is only a way to circumvent the below, having said that, the above also works

    After the user authorizes your application, we redirect the user back to the redirect URI you specified with a verification string in the argument code, which can be exchanged for an oauth access token. Exchange it for an access token by fetching https://graph.facebook.com/oauth/access_token. Pass the exact same redirect_uri as in the previous step:

    via: by: http://developers.facebook.com/docs/api see also: http://forum.developers.facebook.net/viewtopic.php?pid=238371

    0 讨论(0)
  • 2021-01-30 09:46

    Maybe your problem is solved but i yet not found accepted answer from you and maybe this answer helps those who face similar problem

    First we have to Create our Application instance.

    $facebook = new Facebook(array(
      'appId' => '149865361795547',
      'secret' => 'ee827a8df6202e1857b3fc28f3185a61',
      'cookie' => true,
    )); 
    

    easy way to get access_token

    $token = $facebook->getAccessToken();
    

    get page status as you ask in your question

    $response = $facebook->api($pageID . '/feed','get',$token);
    

    thanks..

    0 讨论(0)
  • 2021-01-30 09:47

    You can also get this error if your connect URL isn't a base of your redirect URI. For example

    Connect URL: http://www.example.com/fb/connect/
    
    Redirect URI: http://www.example.com/fb/connect/redirect
    

    I ran into an issue where my redirect URI was the same as the connect URL, but I forgot the trailing / on the redirect URI so FB saw them as different and failed the auth.

    0 讨论(0)
  • 2021-01-30 09:51

    Try to follow the API, i.e without type but add redirect_uri and code (even though we don't need it):

    $token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=<app_id>&client_secret=<app secret>&redirect_uri=<url>&code=<code>');
    
    0 讨论(0)
  • 2021-01-30 09:53

    You can request an access token via terminal (OSX Users) using curl:

    curl -F type=client_cred -F client_id=xxxxxxxxxxxxxxx -F client_secret=c0f88xxxxxxxxxxxxxxxxxx1b949d1b8 https://graph.facebook.com/oauth/access_token
    

    Once you have your access token you can then use it in future curl requests to makes changes via the new graph API:

    Post a message to a profile id:

    curl -F 'access_token=xxxxxxxxxxxxx|mGVx50lxxxxxxxxxxxxhzC2w.'  -F 'message=Hello Likers'  -F 'id=1250000000000905'  https ://graph.facebook.com/feed
    
    0 讨论(0)
  • 2021-01-30 09:55

    Sorry for posting in old question. Due to changes in recent fb access. I have this code working and thought I would post for anyone else requiring help. This method works great with jQuery ajax and eliminates the redirect_uri given example from facebook.

    $ch = curl_init("https://graph.facebook.com/oauth/access_token?client_id=INSERT_YOUR_APP_ID_HERE&client_secret=INSERT_YOUR_APP_SECRET_HERE&grant_type=client_credentials");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 30000);
    $data = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    curl_close($ch);
    
    if ($curl_errno > 0) 
    {
            echo "cURL Error ($curl_errno): $curl_error\n";
    } 
    else 
    {
        echo $data;
    }
    

    outputs a public available access_token for showing to non facebook users. i.e a facebook page feed wall via graph api for websites. access_token=191648007534048|eVilnMh585rlQLZLvBAmqM6s-1g

    phpfacebookoauth2facebook-accesstokenfacebook-oauth

    0 讨论(0)
提交回复
热议问题