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)

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top