Facebook graph API - OAuth Token

后端 未结 11 1852
小鲜肉
小鲜肉 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: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

提交回复
热议问题