Phonegap facebook plugin get users email and birthday? - facebook

I'm using this plugin in my project:
I need to get the users birthday and email once they allow the app to access their information.
And I'm using this code:
function loginWithFB(){
facebookConnectPlugin.login(["public_profile","email"],function(result){
//calling api after login success
facebookConnectPlugin.api("/me?fields=email,name,picture",
["public_profile","email"]
,function(userData){
//API success callback
alert(JSON.stringify(userData));
},function(error){
//API error callback
alert(JSON.stringify(error));
});
},function(error){
//authenication error callback
alert(JSON.stringify(error));
});
}
This will only return the users image URL and their full name. So no email at all!
So i tried to do this:
function loginWithFB(){
facebookConnectPlugin.login(["email","user_birthday"],function(result){
//calling api after login success
facebookConnectPlugin.api("/me?fields=email,name,picture,user_birthday",
["email","user_birthday"]
,function(userData){
//API success callback
alert(JSON.stringify(userData));
},function(error){
//API error callback
alert(JSON.stringify(error));
});
},function(error){
//authenication error callback
alert(JSON.stringify(error));
});
}
But this will give me an error in the alert(); which says 'there was an error making the graph call"! which is not a really helpful error reporting.
Can someone please let me know how I can get the users email and birthday from the graph?
Thanks in advance.
EDIT:
I even tried this and this only returns the user ID instead of email.
function loginWithFB(){
facebookConnectPlugin.login(["email"],function(result){
//calling api after login success
facebookConnectPlugin.api("/me?fields=email",
["email"]
,function(userData){
//API success callback
alert(JSON.stringify(userData));
},function(error){
//API error callback
alert(JSON.stringify(error));
});
},function(error){
//authenication error callback
alert(JSON.stringify(error));
});
}

Related

Facebook Login fails to build

I'm developing an App which requires facebook login. The app could build easily when I didn't had implemented the facebook login.
After implementing it, the app cannot build and it doesn't give me a clear error.
I've already added the facebook plugin "Facebook Connect" to my project.
Here's my code:
if(window.navigator.onLine)
{
setTimeout(function(){
var fbLoginSuccess = function (userData) {
console.log("UserInfo: ", userData);
}
facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
function loginError (error) {
console.error(error)
}
);
},500);
}
On the plugin I already set the correct AppId and AppName.
When I try to test, by building it, nothing happens. It gives me an error when I try to upload it. But it doesn't say cleary what is the error.
you can try read more here
facebookConnectPlugin.login( ["public_profile","email"],function (response) {
if(response.authResponse.userID!=''){
facebookConnectPlugin.api(response.authResponse.userID+"/?fields=id,email,first_name", ["public_profile"],
function (response) {
console.log(response);
},
function (response) {
console.log(response);
});
}
},
function (response) {
console.log(response);
});
let me know if its not working

Not able to get facebook userdata in Smartface App Studio

I tried to implement facebook login for my app.
After success login, i am trying to get userdata by following code,
Facebook.Social.userDetails({onSuccess : function (e) {
alert(e.name);
},
onError : function () {
alert(e.message);
}
});
But, both onSuccess and onError events is not firing.
Can any one help me pls.
Thanks in advance.
Got it. :)
Should use Social.Facebook.userDetails({}) rather than Facebook.Social.userDetails({});
Thanks.

What is the error in the following code

Here is a function which is call when user click a button to attend a event on facebook, these following code get the login information from user and add there particular event to the user fb event to attending the event.
These code is giving me the syntax error, i does not Know what is the error. Please help its needy.
function gogingtoevent() {
FB.login(function(response) {
if (response.status == 'connected') {
FB.api('/816891388384961/attending',
function (response) {
if (response && !response.error) {
alert('Attending');
}else{
alert (JSON.stringify(response));
}
});
}else{
alert('Not Responding');
}
});
}
You need to do a POST request to this edge, and you need the rsvp_event permission.
It's all in the docs:
https://developers.facebook.com/docs/graph-api/reference/v2.3/event/attending#publish
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#adding

auth.logout is not working in my app using firebase facebook authentication

I have tried basic steps of Firebase Facebook authentication. So in my app the user can successfully log in using Firebase Facebook authentication. But I have a problem in logout.
I used logout button and bind click event on that, as shown below:
$(function(){
$('#lgout').click(function(){
auth.logout();
});
});
For login I use this code:
var chatRef = new Firebase('https://my-firebase-url');
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
// an error occurred while attempting login
alert("please login first");
} else if (user) {
// user authenticated with Firebase
//alert('User ID: ' + user.id + ', Provider: ' + user.provider);
$.ajax({
type: "GET",
url: "https://graph.facebook.com/"+user.id,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$('#user').text("Welcome "+data.name);
}
});
} else {
// user is logged out
//auth.login('facebook');
}
});
auth.login('facebook');
In login also, I got one problem as you can see in else part I used auth.login('facebook'); that is not working showing error
auth is not defined. But if I used outside of else then it working fine.
Please help me to figure out this problem.
Separate from the issue regarding auth.logout(), you should never call auth.login('facebook'); from within this callback. Rather, it should be called after a user click event, as your browser will prevent the Facebook pop-up from launching.
From https://www.firebase.com/docs/security/simple-login-overview.html:
Third-party authentication methods use a browser pop-up window to
prompt the user to sign-in, approve the application, and return the
user's data to the requesting application. Most modern browsers will
block the opening of this pop-up window unless it was invoked by
direct user action.
For that reason, we recommend that you only invoke the "login()"
method for third-party authentication methods upon user click.

facebook javascript sdk not posting via ajax using fb.api and .post

I have a facebook application. The users are logged in and authorized. I am calling fb.api to post the user's name to my textfile. The alert shows the name. The post doesn't seem to post to my aspx file..
FB.Event.subscribe('edge.remove', function (href, widget) {
alert("outside");
FB.api('/me', function (response) {
alert(response.name);
var paramsObj = { 'name': response.name };
$.post("ajax/delete.aspx", paramsObj);
});
window.location.replace("Default.aspx");
});
I've updated my code to include showing the encapsulating facebook calls to give a broader picture as well as to include #Lix changes [thank you!].
Few things you might want to try :
Define your post parameters object before and only place the objects name in the jQuery $.post method.
Wrap your json keynames with quotes.
var paramsObj = { 'name':response.name};
$.post("ajax/write.aspx", paramsObj );
Use firebug/chrome developers tools to debug the AJAX request and see if any value is being passed and/or use breakpoints in your code to help you understand where the value is missing.
The page was being redirected prior to the api call/ajax post. This is what worked:
FB.Event.subscribe('edge.remove', function (href, widget) {
FB.api('/me', function (response) {
var paramsObj = { 'name': response.name };
$.post("ajax/delete.aspx", paramsObj);
window.location.replace("Default.aspx");
});
});