开发者

Adding a test user in graph api (javascript sdk)

I am trying to add a couple to test users to an app I'm developing using google app engine and the javascript sdk. Following this link:, I tried this code:


FB.api ('/app_id/accounts/test-users', 'post', {installed:'true', permissions:'read_stream'}, function (response) {
    alert (response.id);
});

(app_id was changed to the App ID as obtained in http://www.facebook.com/developers/apps.php)

But I get a popup "undefined". What is wrong with this code? I could not find any example for the javascript s开发者_C百科dk.

As per the same facebook help page, response is supposed to be:


{ 
  "id": "1231....",  
   "access_token":"1223134..." , 
   "login_url":"https://www.facebook.com/platform/test_account.." 
}

BTW, if I log in as myself,


FB.api('/me', function(user) {
    welcomeMsg (user);
});

works just fine, so it's not a problem with app activation.


I don't think it's possible to perform this type of task using the Javascript SDK, which is intended to make calls on behalf of a user, not an app. For this type of call, it's necessary to authenticate as the app, and for that you need the app OAuth token and secret, which aren't available via Javascript (nor should they be, for security reasons). So the best solution here is to make this call serverside. To do so, you should follow the "App Login" instructions here to get an app access token, and then pass that token in to the /app_id/accounts/test-users API call (as the "access_token" param)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜