2
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?

Pang
  • 9,564
  • 146
  • 81
  • 122
user3085287
  • 23
  • 1
  • 3

1 Answers1

7

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.

Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
  • Thank you- this worked. My steps: 1) Generate the token when the user logged in (under FB.login).. Token = response.authResponse.accessToken; 2) Store token on server side for easy access 3) Use AJAX to access the token when calling Facebook through FB.api calls – user3085287 Dec 10 '13 at 07:24