6

I have the follwing code and would like to take the email address and other details of facebook user. This is the code that I have done.

FB.login(function(response) {
      if (response.authResponse) {
         //updateUserInfo(fb_id);
        console.log(response.authResponse);
        updateUserInfo(response.authResponse.userID);
        $.ajax({
           dataType: "json",
           url: 'http://graph.facebook.com/'+response.authResponse.userID+'/ fields=id,name,birthday,email,gender,hometown,location',
           success: function(data){
                fb_data = data;
               console.log(data);
            }});
 },{scope:'email'});

I am unable to get get the following details:

  1. birthday
  2. email
  3. Location
  4. hometown

However, I am able to get the first name and id.

If I am supposed to use the access token, how am i supposed to put it in the query? The email address is the vital information as my system identifies user by email address.

madi
  • 5,612
  • 5
  • 36
  • 48
  • 1
    If user are request their own, then they are require to grant the APP with email, user_birthday, user_hometown, user_location permission for your case. If user are request for their friends, then friends_birthday, friends_hometown, friends_location should granted. To access friend's email, there's a known bug as discussed at http://stackoverflow.com/questions/16630972/facebook-graph-api-wont-return-email-address – 林果皞 Jan 10 '14 at 04:21

2 Answers2

3

You need following permission from user to get the data from Facebook.

  1. user_birthday for birthday
  2. email for email
  3. user_location for Location
  4. user_hometown for hometown

You can check this or this for other permissions and uses.

Then you will get the access token once user click on your Login button and authorize your App.

amrendra
  • 345
  • 2
  • 12
2

You dont have to use the ajax call after FB.login, you can use FB.api doc , which will ensure that the access token that you have obtained while logging in (requiring email access) will be used for accessing the data

jacquard
  • 1,307
  • 1
  • 11
  • 16