0

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)

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.