0

I was debugging an older script and came to the part where it should query a some Data of a Facebook user and store it into a Database.

Some of the scopes like publish_stream have been deprecated and so i replace it with "publish_actions". At least there is something i couldn't figure out. I would like to query the first and last name of the user but this reponse stays empty, the only that works is the thumbnail and the user ID.

So here are the scopes (i know public_profile is not necessary but facebook recommends it).

//function handleFacebookAuth(callback) {
function handleFacebookAuth(callback) {
    var permissions = '';
    //noinspection JSUnresolvedVariable
    if (window.extendedPerms) {
        permissions = 'public_profile,email,publish_actions,user_likes,' + window.extendedPerms;
    } else {
        permissions = 'public_profile,email,publish_actions';
    }
    if (accessToken != null && userId != null) {
        callback(accessToken, userId);
    } else {
        FB.login(function (response) {
            if (response.authResponse) {
                userId = response.authResponse.userID;
                accessToken = response.authResponse.accessToken;
                callback(accessToken, userId);
            } else {
                $("#white-wall").hide();
            }
        }, {scope: permissions});
    }
    return false;
} 

And here the query to the Data

function sendData(moves, seconds) {
    FB.api('/me', function (response) {
        var data = {
            access_token: accessToken,
            flag: 'data',
            fbuid: response.id,
            moves: moves,
            seconds: seconds,
            fname: response.first_name,
            lname: response.last_name,
            email: response.email,
            gender: response.gender
        };
        userId = response.id;
        $.ajax({
            url: "ajax.php",
            data: data, dataType: 'html', method: "post",
            error: function (data) {
                alert(data.responseText);
            },
            success: function (data) {
                console.log(data);
                //$( "#gameresults" ).html( data);
                $('#gameresults').html(data);
                $("#triggerbtn").fancybox({
                    'width': 480,
                    'height': 550,
                    'autoSize': false,
                    'overlayShow': false,
                    'scrolling': 'no'
                });
                $("#triggerbtn").trigger('click');
                //window.top.location.href = data;
            }
        });
    });
}

I hope that maybe someone see a mistake in it, i really can't figure out what is wrong with it, maybe the issue might be somewhere else and it would be great to hear that my code above is okay.

Kara
  • 6,115
  • 16
  • 50
  • 57
Deex
  • 317
  • 2
  • 13
  • 1
    You need to specify the fields you want. Just search StackOverflow this question comes up every day – WizKid Apr 03 '16 at 00:37
  • Oh okay seems they changed more.From what i understood is that i have exactly to query the fields since API 2.4. Thank you – Deex Apr 03 '16 at 04:53

1 Answers1

0

Okay thanks WizKid's hint the solution was pretty simple I added to /me

FB.api('/me?fields=id,first_name,last_name,email,gender', function (response) {

That was all..

Deex
  • 317
  • 2
  • 13