Facebook Registering Achievement access_token issue

Go To StackoverFlow.com

0

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.

2012-04-04 21:23
by Enzo


0

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)

2012-04-04 22:06
by Igy
I'm aware. I've verified the access_token I'm using is the app's access token as per the graph API link I mentioned above. It brings back the app's information, nothing about the user - Enzo 2012-04-04 22:39
Sorry, i may have misunderstood - You should be able to use the app access token retrieved via the method in the link i shared - this should allow you to read achievement types, create achievement types and post new achievements for a user who has granted you publish_actions permission Caveat: if your app settings say it's a native/desktop app the app secret won't be trusted and you can't use thi - Igy 2012-04-05 10:50
Sadly, it doesn't work, I just get the error constantly.. sigh.

I somehow managed to get 2 achievements in, which I can pull and grant to users, but I can't add new ones, edit the 2 that I got in somehow, nor delete them. It's becoming rather frustrating - Enzo 2012-04-05 14:03

There may be an open bug report about that if you can reliably (or unreliably) reproduce the fact that you're doing everything correctly and it's still not workin - Igy 2012-04-05 15:33
Finally fixed this.. you can't use the PHP SDK nor the other stuff they tell you to use in the documentation.. I've updated my main post with the way you have to get the right access token, which is DIFFERENT than the one that their OpenGraph stuff tells you it is - Enzo 2012-04-05 16:01
Ads