Question

I'm working on a small game, where the user can play one time each day. I will track this via the Facebook ID.

All the backend is done, and the game works when I manually insert my Facebook ID and access token.... But how do I get the access token from the Facebook API?

I tried this:

FB.init({ 
            appId: 'my app id', 
            channelURL : '//my domain/channel.html', // Channel File
            cookie: true, 
            xfbml: true, 
            status: true 
        });

        FB.getLoginStatus(function (response) {
            if (response.session) {
                alert(response.session.access_token);
            } else {
                alert("not logged in");
            }
        });

But it always alerted "Not logged in", even if I'm logged into Facebook.

(My domain and app ID is hidden due to privacy of my client)

Was it helpful?

Solution

You should definatly Migrate to oAuth2, (if you haven't - you should), then you can try this :

FB.getLoginStatus(function(response) {
    if (response.authResponse && response.status=="connected") {
        uid = response.authResponse.userID;
        token = response.authResponse.accessToken;
        // user is logged in
    }
}); 

For the javascript SDK all you have to do in order to migrate to oAuth2 is add an additional parameter to the initialization :
oauth : true

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top