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
Related
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.
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!
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.
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/
I need using javascript to check if the current user is fan of my page.
I goto here https://developers.facebook.com/docs/reference/rest/pages.isFan/. In Test Console I don't understand about Application parameter?
I using this code below, but it's always alert "You like the Application" for any user even guest
window.checkDoesLike = function() {
FB.api({ method: 'pages.isFan', page_id: '138992766181857' }, function(resp) {
if (resp) {
alert('You like the Application.');
} else {
alert("You don't like the Application.");
}
});
};
I've written an extended tutorial about this here.
There are a couple of points to highlight:
You are missing the uid parameter
using if(resp) is not enough
Better code:
FB.api({ method: 'pages.isFan', page_id: 'page_id_here', uid: 'user_id_here' }, function(resp) {
if (resp == true) {
alert('user_id likes the Application.');
} else if(resp.error_code) {
alert(resp.error_msg);
} else {
alert("user_id doesn't like the Application.");
}
});
Quoting:
Once again, you need to check the response of the call if true or
not…using if(resp) is NOT enough! The example in the Facebook
JavaScript Test Console is a bit misleading (the does-like example),
since if you don’t grant the user_likes permission and just try it
with uid: '579187141' it would result that the user likes the
application which is not true!
P.S: I just decremented my user id to get the above user which (it
seems) he has a strict privacy for pages he likes!