开发者

OAuthException (#15) "This method must be called with an app access_token" while trying to post achievement

I'm constantly getting the OAuthException (#15) "This method must be called with an app access_token" while trying to register achievement for my app in the following way:

FB.api("/APP_ID/achievements",
'post',
{achievement: FULL_ACHIEVEMENT_URL, access_token: ACCESS_TOKEN, display_order: 1},
function(response){
    getFlashMovieObject(referrer)开发者_C百科.fbDataCallback(response);
});

Achievement file structure has been verified and is correct, ACCESS_TOKEN value is OK too - if I change HTTP method to 'get' I receive an array that stores registered achievements.

Can you, please, tell me how to register achievements correctly using the JS API methods?


You can't call methods which require app access token from client SDKs such as javascript SDK. Javascript SDK will always send user access token implicitly for API calls. This is by design due to security reasons.

hope this helps


Seems there is no answer. I've tried it once again today - and it simply starts working.)

NOTE: don't expect for a POST request to appear in your sniffer (as I did:)) even if you have specified respective 'method' value while calling FB.api() - any way you'll see the GET one. It's a forced workaround and it works.


My solution to this problem was grabbing the APP access token with PHP and then passing that token as part of the post object. The USER access token will not work.

I had to do this for a Flash game I was building which uses the Javascript SDK through External interface. You can't get the app access token with Javascript because you would reveal the app secret which is a security issue.

<?php

$APPLICATION_ID = YOUR_APP_ID;
$APPLICATION_SECRET = YOUR_APP_SECRET;

$token_url =    "https://graph.facebook.com/oauth/access_token?" .
        "client_id=" . $APPLICATION_ID .
        "&client_secret=" . $APPLICATION_SECRET .
        "&grant_type=client_credentials";
$app_token = file_get_contents($token_url);

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜