Cordova: Can't able to get user information, it shows 'malformed access token'

115 Views Asked by At

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

0

There are 0 best solutions below