Facebook Plugin - PhoneGap

0

I'm using a PhoneGap plugin to log in with Facebook, it's working perfectly, I can get the email and user id, now I needed to put that data in a JSON so I could work with it via ajax.

follow the code:

HTML

        <div class="event listening button" onclick="login();">Logar com Facebook</div>
        <div class="event listening button" onclick="apiTest();">Mostrar Dados</div>
        <div class="event listening button" onclick="logout();">Fazer Logout</div>

JS

        var login = function () {
          if (!window.cordova) {
             var appId = '305528339609022';
             facebookConnectPlugin.browserInit(appId);
          }
          facebookConnectPlugin.login( ["email"], 
             function (response) { alert(JSON.stringify(response)) },
             function (response) { alert(JSON.stringify(response)) });
        }

        var apiTest = function () { 
            facebookConnectPlugin.api( "me/?fields=id,email", ["user_birthday"],
                function (response) { alert(JSON.stringify(response)) },
                function (response) { alert(JSON.stringify(response)) }); 
        }

        var logout = function () { 
            facebookConnectPlugin.logout( 
                function (response) { alert(JSON.stringify(response)) },
                function (response) { alert(JSON.stringify(response)) });
        }

can see that I make login() after clicking the show data , an alert will appear for me showing the data. Now, I needed to put it in an array, to get via ajax ...

You can see in the air

link

RIGHT NOW I GET THE DATA, IT IS OBJECT

MY OBJECT

                var apiTest = function () { 
                facebookConnectPlugin.api( "me/?fields=id,email", ["user_birthday"],
                    function (response) { 
                      dados = response;
                    });
            }

The object is called "data", how can I get that object and make a json_enconde() ?

    
asked by anonymous 06.08.2014 / 19:32

1 answer

0

Quite simply, you define a variable outside the call to api and within the invocation call to response in that variable ... how you want an object, you do not JSON.stringify() , stringify is just to represent the object in a string json (to display in an alert as there is for example)

   var dados;  

   var login = function () {
      if (!window.cordova) {
         var appId = '305528339609022';
         facebookConnectPlugin.browserInit(appId);
      }
      facebookConnectPlugin.login( ["email"], 
         function (response) { alert(JSON.stringify(response)) },
         function (response) { alert(JSON.stringify(response)) });
    }

    var apiTest = function () { 
        facebookConnectPlugin.api( "me/?fields=id,email", ["user_birthday"],
            function (response) { 
              dados = response;
              alert("sucesso !!!"+JSON.stringify(response));
            },
            function (response) { alert(JSON.stringify(response)) }); 
    }

    var logout = function () { 
        facebookConnectPlugin.logout( 
            function (response) { alert(JSON.stringify(response)) },
            function (response) { alert(JSON.stringify(response)) });
    }
    
06.08.2014 / 19:47