FB.api error.. “An access token is required to request this resource”

大城市里の小女人 提交于 2019-12-24 00:37:45

问题


FB.api('/1354376857/groups', function(response){
     Data = response.name;
     alert(Data);

     if (response.error) {
        alert(response.error.message);
     }  
});

The outputted error message reads: "An access token is required to request this resource" and Data content is undefined for my Facebook app. The user is successfully logged in and the "user_groups" permission has been approved by the user.

I was under the impression that FB.api automatically sets the access token. Any thoughts on why this error is occurring?


回答1:


Change your code to this

var token = "YOUR_TOKEN";
FB.api('/1354376857/groups', function(response){
     Data = response.name;
     alert(Data);
     if (response.error) {
        alert(response.error.message);
     }  
}, {access_token: token});

You must pass your access token every time you do a request to the facebook api.



来源:https://stackoverflow.com/questions/20485560/fb-api-error-an-access-token-is-required-to-request-this-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!