问题
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