Facebook birthday is not coming when logging in - facebook

I am using Facebook login button with JavaScript. Everything is working fine but my client needs to fetch "birthday" when any user log-in with Facebook.I have written the code but for some fb ids it is giving me the Birhtday while in some cases it is not giving.
I have checked answers on google already and have done almost everything but no success.
Here is my code I am using
HTML CODE
<a onclick="fb_login();" href="javascript:void(0);"><i class="fa fa-facebook"></i> <span>Log in with Facebook</span></a>
JavaScript Code
function fb_login(){
FB.login(function(response) {
if (response.authResponse) {
//console.log('Welcome! Fetching your information.... ');
//console.log(response); // dump complete info
access_token = response.authResponse.accessToken; //get access token
console.log(access_token);
user_id = response.authResponse.userID; //get FB UID
FB.api('/me', function(response) {
console.log(response);
user_email = response.email; //get user email
first_name = response.first_name; //get first name
last_name = response.last_name; //get last name
full_name = response.name; //get last name
fb_id = response.id; //get id
birthday = response.birthday; //get id
alert(birthday);return false;
// you can store this data into your database
var data = {
action: 'mb_facebook_login',
user_email:user_email,
first_name:first_name,
last_name: last_name,
full_name:full_name,
fb_id:fb_id,
birthday:birthday
};
jQuery.post(ajaxurl, data, function(ajaxresponse) {
console.log(ajaxresponse);
if(ajaxresponse=='loggedin')
{
//location.reload();
}
});
});
} else {
//user hit cancel button
console.log('User cancelled login or did not fully authorize.');
}
}, {
scope: 'user_birthday,email,user_location'
});
}
I have also made my birthday to public also set the permission here but it´s not working.
Please help me in this.Thanks in advance!

https://developers.facebook.com/docs/apps/changelog
Apps requesting more than public_profile, email and the user_friends permission must be reviewed by Facebook before those permissions can be requested from people.
That is one reason why it does not work for some people, without review it will only work for users with a role in the App (developer, tester, admin).
Another reasons could be that some users did not set a birthday. Not sure if that is possible, but it is worth testing.

Related

Getting Facebook Interests graph api call

I am trying to get the users liked Facebook pages, here is my code:
exports.checkUserInterests = function (fbaccountID,fbModule) {
var facebookModule = fbModule;
;
//code to get the list of facebook likes for any given user
facebookModule.requestWithGraphPath('me/interests', {}, 'GET', function(e) {
if (e.success) {
alert(e.result);
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response');
}
});
};
My Permissions is set as following:
//set permissions for graph api
var permissions = ['user_friends', 'user_interests', 'user_birthday', 'user_photos', 'basic_info'];
I an returning an empty json array, is my request correct?
Thanks
I use a different call to get the Facebook Likes of a user, maybe thats the problem.
For example, if I want to know if the user likes a page with id: xxxxx, I do a GET call to "me/likes/xxxxxx" and see if the result is true.
For this to work, you should have the permissions to user_likes.

Facebook Graph API Posting a Comment as User

I am trying to build a comments method within a website without the Facebook comments plugin.
It's a photogallery portion of a website and all the photos are actually hosted on the business Page, I'm doing this to make use of FBs uploading, resizing/rotate etc rather than having to build that myself too.
As a happy bi-product to this I figured I could link comments on the website with comments on FB and have a syncrhonised comments system whereby comments posted on either site (my website or FB) will show equally on either site.
So, I have worked out how to post the comments, but it is always posting as the Business Page, not the logged in user.
This code posts the comment, the variable obj is the ID of the photo on Facebook. msg is obviously the comment text. I have setup methods to get the correct permissions where required which are called if the response from the post states that this is needed.
FB.api('/' + obj + '/comments',
'post',
{ "message": msg,
"access_token": accessToken,
"from": uid
}, // do the post
function (response) { // check the response
if (!response || response.error) { // if there's an error
// DO STUFF WITH ERRORS/REQUEST PERMS ETC
} else {
alert("Msg posted id: " + response.id);
};
});
Everything above works, but when the comment appears, it is always showing from: my Page ID not, what I need which would be from: my user id
accessToken and UID is being retrieved as follows:
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
uid = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
}
});
The para from in the first function there posts the User ID, NOT the page ID, but whether that para is there or not, it always posts the comment as the Page.
It's frustrating the hell out of me as so far this has been pretty simple to achieve!

How to get user_id in facebook when has logged facebook but not authorized?

FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
alert(uid);
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
// logged in and connected user, someone you know
var uid = response.id;
alert(uid);
} else {
// the user isn't logged in to Facebook.
alert("the user isn't logged in to Facebook.");
}
});
How to get uid when not_authorized ?
How to get uid when not_authorized ?
Not at all. Facebook does not give you such information, unless the user has authorized your app.
It’s a matter of privacy – think about it, every site on the net could set up their own app, and would get your FB user ID once you browse it. Would you want f.e. a random p0rn site that you might get redirected to from somewhere else without you even wanting this to happen to get your Facebook user ID? Of course you would not.

facebook fan gate only work with admin account Javascript

I have a facebook fan gate in my facebook app (iframe app), but it's only working when logged in with the administrator account. When i was testing the app without sandbox mode with normal users they get stuck in the not fan section, but they are fans.
I have checked the page ID, it's correct.
Thanks for help
FB.getLoginStatus(function (response) {
if (response.status == 'connected') {
var user_id = response.authResponse.userID;
var page_id = "[pageid]";
var fql_query = "SELECT uid FROM page_fan WHERE page_id =" + page_id + " and uid=" + user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#container").show();
$("#container_notlike").hide();
$("#notloggedin").hide();
alert("User like page")
}
else {
$("#container_notlike").show();
$("#container").hide();
$("#notloggedin").hide();
alert("User NOT like page")
login();
}
});
} else {
$("#container_notlike").hide();
$("#container").hide();
$("#notloggedin").show();
login();
}
});
}
init();
From the comments, it seems your Login code wasn't actually asking for the user_likes permission which you'll need to check if the page is liked by users who don't have completely Public likes
Re: the other question in the comments, see https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ - subscribe to the edge.create callback and you'll be notified when the like button is clicked

How to get facebook user id without calling FB.getLoginStatus and promting user to grand access for public information

I am developing asp.net web site to be facebook application.
I am trying to make "Facebook Like Gate" to promt user Like my page before he can see the application. For example https://www.facebook.com/AvonProductsInc?sk=app_188308831197082.
The problem is that application above does not aks me for permission to get my basic information, but i have to promt user give me such permission before i can use following code to get user_id and check wether he has already Liked my page:
function checkFBlike() {
//FB.login
FB.getLoginStatus(function (response) {
var r = response;
if (response.status == "connected") {
var user_id = response.authResponse.userID;
var page_id = "341342102543433"; //341342102543433 168619489865949
var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id;
var the_query = FB.Data.query(fql_query);
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
//jQuery("#container_like").show();
fbLikeGateHide();
//here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.
}
else {
//and here you could get the content for a non liker in ajax...
}
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook, but not connected to the app
showFbLogin(); //display Facebook Login button
}
else {
// user is not logged in
}
});
}
function showFbLogin(){
FB.login(function(response) {
var r=response;
});
}
Since you're going to be like the avon app (specifically a page tab application) You should look at the signed_request parameter coming from the HTTP POST that Facebook does when your page is a canvas app. You really don't need to do any client side checks.
For more information about the signed_request, see: http://developers.facebook.com/docs/authentication/signed_request/