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 this data in a JSON for me to work with it via ajax.
follows 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)) });
}
you can see that I do the login()
then I click on the show data, there will appear an Alert for me showing the data. Now, I needed to put it in an array, to pick up via ajax...
you can see in the air
http://www.petfy.com.br/facebookconnect/www/
RIGHT NOW I GOT THE DATA, IT IS IN OBJECT
MY OBJECT
var apiTest = function () {
facebookConnectPlugin.api( "me/?fields=id,email", ["user_birthday"],
function (response) {
dados = response;
});
}
the object is called "data", as I can take this object and make a json_enconde()
?
put in an array to catch via ajax ? xDD
– Enoque Duarte
in apiTest(), the answer you receive is already a js Object, just store in a var qlqer
– Enoque Duarte
@What would you look like? var id = JSON.stringify(Answer); ?
– Furlan
you can declare var 1º at the top, where you want (var data), and then within the function you give the value (data = Sponse),,,,,, if you want an Object you don’t stringify xd, stringify is to transform jobject into a json string
– Enoque Duarte
I’ll put the code in an answer for you to see
– Enoque Duarte
@Enoqueduarte I understood, now, how to for example, to catch her via ajax?
– Furlan
what do you mean how to catch her via ajax ? the variable is set, just use it :)
– Enoque Duarte
uhm ? that code will hit the server ?? you are using Node.js ?
– Enoque Duarte
I think you’re confusing xd, javascript runs client-side
– Enoque Duarte
Yes @Enoqueduarte I meant that the code that connects with facebook will be on the server-side, for me to get this data on the server I have on client-side! understands?
– Furlan
Let’s go continue this discussão in chat.
– Enoque Duarte