0

I am about to finish my cordova application where i am using the facebook social login. I am trying to access the user information from the graph API that openfb.js is calling. My code snippet is this:

                        function login() {
                        openFB.login(
                                function (response) {
                                    if (response.status === 'connected') {
                                        alert(JSON.stringify(response));
                                        FACEBOOK_TOKEN = response.authResponse.accessToken;
                                        var message = "Connected to Facebook_____";
                                        alert('Message is :' + message);
                                        alert('Access token is :' + FACEBOOK_TOKEN);
                                        getInfo(response.authResponse.accessToken);
                                    } else {
                                        var errorMessage = 'Facebook login failed: ' + response.error + "_____";
                                        alert(errorMessage);
                                    }
                                }, {scope: 'email,public_profile,user_birthday,user_location'});
                    }

                    function getInfo(access_token) {
                        openFB.api({
                            path: '/2.5/me?access_token=' + access_token,
                            success: function (data) {
                                alert(JSON.stringify(data));
                                var message = "Logged in with Facebook as " + data.name + "_____";
                                alert(message);
                            },
                            error: errorHandler
                        });
                    }

                    function errorHandler(error) {
                        var errorMessage = error.message;
                        alert('Error is : '+errorMessage);
                    }

Here in this case when i am getting the access token of the user but when i pass it to graph API that is in the get info function, then it shows me the error:

Error is : Malformed access token CAANoTLg2W..........

I am not able to debug the error ocuring here. Please help me resolve it. Thank in advance for any response.

enter image description here

  • 2
    Your alert message suggests that the access token is appended twice – `[a_t]?access_token=[a_t]`. Are you sure you need to pass the access token manually? I’d expect such a library to handle that itself internally. – CBroe Jan 06 '16 at 11:08
  • ok let me check. i am trying it to store it in localstorage as sessionstorage is not accessible in cordova –  Jan 06 '16 at 11:15
  • hey u are right but then the response i am getting is like i am getting only name & some id in the JSON i am receiving. what do i have to do if i need the user email,dob,gender??? –  Jan 06 '16 at 11:27
  • 1
    Since API v2.4 was introduced, you need to specifically ask for the fields you want. – CBroe Jan 06 '16 at 12:14
  • ok i am getting the email,gender as that is the part of user_profile but i am not getting user_birthday & user_location. what i have to do for that? –  Jan 07 '16 at 09:28
  • Did the user grant the permissions? Did you ask for the right fields? – CBroe Jan 07 '16 at 10:16

0 Answers0