0

I am working on cordova facebook login, with the phonegap-facebook-plugin,

I am using the following function after checking the login status of the user with FB.getLoginStatus

function processFacebook(token) {
  FB.api('/me', 'get', {
    access_token: token
  }, function(response) {
    alert(response);
  });
}

but, I am unable to receive any response. Can anybody point out where I am going wrong? I took the reference from this , but the method seems not to work. Here's the link to the original index.js and index.html file

Community
  • 1
  • 1
isnvi23h4
  • 1,910
  • 1
  • 27
  • 45

2 Answers2

1

Try this stuff.

To get Access Token.

var fbLoginSuccess = function (userData) {
        alert("UserInfo: ", userData);
        facebookConnectPlugin.getAccessToken(function(token) {
        alert("Token: " + token);
    });
}

Get user Profile data.

var fbLogin = function() {
    facebookConnectPlugin.login(["public_profile", "email", "user_birthday", "user_location"],
        function(response) {
            console.log("Login Response :" + JSON.stringify(response));
            //alert("Login Response :" + JSON.stringify(response))
            this.authId = response.authResponse.userID;
            if (response.status == "connected") {
                facebookConnectPlugin.api("/" + response.authResponse.userID, ["public_profile", "email", "user_birthday", "user_location"],
                    function(result) {
                        this.email = result.email;
                        this.firstname = result.first_name;
                        this.lastname = result.last_name;
                        this.birthdate = result.birthday;
                        this.city = result.location.name;
                    },
                    function(error) {
                        alert("Failed: " + error);
                    });
            }
        },
        function(response) {
            alert("Other Response : " + JSON.stringify(response))
        });
}

It will give you all the Relevant details of User Profile.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
  • hi, thanks for the answer, I am working on this, can you also tell me how do you find the user parameter names? because the graph api explorer seems not to work https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.6 – isnvi23h4 Apr 25 '16 at 14:34
  • @souparnomajumder I didn't get you ! can you pls explain more. – Jay Rathod Apr 25 '16 at 16:38
  • how did you know that "public_profile", "email", "user_birthday", "user_location", will be the parameter names? the facebook graph api explorer (the link that i have mentioned in the comment) doesnot seem to work, so if i am to include other user parameter int how am i to find that out? – isnvi23h4 Apr 25 '16 at 17:55
  • @souparnomajumder That all parameters are mentioned in plugins it self which you are using you don't need to check it for official development. this plugins are created using that all stuffs so it contains all the required functionalities of official development. you just need to use this try and check. – Jay Rathod Apr 25 '16 at 18:06
0

try this code

var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
facebookConnectPlugin.getAccessToken(function(token) {
    alert("Token: " + token);
}, function(err) {
    alert("Could not get access token: " + err);
});

}

Kishore Vaishnav
  • 510
  • 3
  • 17