Question

Solution Edit: Turns out you can't use the PHP SDK to return the correct App Token, nor can you hit the OpenGraph options in the App section of the Developer site, click "Get Code" and grab the app access token from there.. you have to do this:

$token_url = 'https://graph.facebook.com/oauth/access_token?client_id=' . $fbConfig['appId'] . '&client_secret=' . $fbConfig['appSecret'] . '&grant_type=client_credentials';
$accessToken = explode('=',file_get_contents($token_url));
$accessToken = $accessToken[1];

Original issue: Using the PHP SDK, I've been trying unsuccessfully in registering my achievements. I keep getting the following error: "This method must be called with an app access_token."

However, when I enter the token I'm using into opengraph (https://graph.facebook.com/app?access_token=ACCESS_TOKEN) I get my app information correctly.

Here are the methods I've tried thus far in registering my achievements:

$param = array(
    'access_token' => $accessToken,
    'achievement' => 'http://domain.com/path/to/my/achievement/page',
    'display_order' => $achievements['achievementWeight']
);
$achievement = $fb->api('/'.$this->CI->config->item('app_id').'/achievements', 'POST', $param);

$superCurl = "curl -F 'achievement=" . $achieveUrl . "&access_token=" . $accessToken . "' https://graph.facebook.com/" . $appId . "/achievements";
exec($superCurl,$result);


$url = 'https://graph.facebook.com/' . $this->CI->config->item('app_id') . '/achievements?access_token=' . $accessToken;
$c = curl_init ($url);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $param);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
if(curl_errno($c)){
    $this->CI->firephp->log(curl_error($c));
}
$page = curl_exec ($c);
curl_close ($c);

Everything always comes back saying it needs an access_token.

Was it helpful?

Solution

See the Authenticating as an App document - you must use the app's access token which allows you to act on behalf of the app - a user access token won't suffice for this case (and several others)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top