How can I get using the JS api only the install time of the currently used facebook application?
In general I would like to verify that the user that currently online is a new user and not already registered returning user.
You can use FB.getLoginStatus as recomended here it can tell you weather visitor are logged into facebook and if so if they are registered with your application.
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;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
Related
I have continue with facebook button in the user's profile page.
that opens facebook's permission page and saves facebook user ID to our DB, that makes a pair with his account.
Now I want to makedisconnect button that sends permission delete requests to facebook and delete entry from our DB.
I used FB.Event.subscribe('auth.authResponseChange', event); listener but the authResponse doesn't change when the user logs off from FB, on the other web browser tab.
if(fb_status === "connected" && fb_userID.length > 0){
removeFbUser(fb_userID); // deletion in DB
}else if (fb_status === 'not_authorized'){
//error message
}else{
// user is logged out
FB.login(function(response) {
if(response.status === "connected"){
removeFbUser(response.authResponse.userID);
fb_userID = response.authResponse.userID;
}else{
// error
}
fb_status = response.status;
});
}
I'm also getting this error message from facebook sdk :
You are overriding current access token, that means some other app is expecting different access token and you will probably break things. Please consider passing access_token directly to API parameters instead of overriding the global settings.
I am creating facebook application. If user is not logged on facebook I redirect them to FaceBook login that redirects to my application URL after they logged to facebook. Problem is that user is redirected to facebook.com insted of facebook application URL
Here is code that I am using to check if user logged to FaceBook
function statusChangeCallback(response) {
if (response.status === 'connected') {
// Logged into your app and Facebook.
FillInfo();
} else if (response.status === 'not_authorized') {
window.top.location("https://apps.facebook.com/memorygameonfb/?fb_source=bookmark&ref=bookmarks&count=0&fb_bmpos=3_0")
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
window.top.location = "https://www.facebook.com/login.php?api_key=id&skip_api_login=1&display=page&redirect_uri=https://apps.facebook.com/memorygameonfb/?fb_source=bookmark&ref=bookmarks&count=0&fb_bmpos=3_0"; }
}
The reason they are being redircted to facebook.com is becasue that is where you are sending them
You need to create $params so when your user logs in you can redirect them to your app.
You can find the dox on this Here
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://www.myapp.com/post_login_page' //This redirects to ur APP!
);
$loginUrl = $facebook->getLoginUrl($params);
I personally am not great with JS I use php for facebook api I think it is easier to manage then the JS API
If you would like to download a basic app allowing you to login with php
Click Here
and follow the readme file for instructions.
I'm using FB.getLoginStatus() to check for login which will display authorization dialog in case it's needed.
the case here, if that the user unchecked email from the below screen, the screen will not attempt to re-ask the user by displaying the dialog, and calling FB.login will result in a warning that user is already authenticated. there is a way i can pass a scope with recheck option to FB.getLoginStatus()? or any other solutions to set me on the right track
function checkLoginState() {
FB.getLoginStatus(function (response) {
//console.log('statusChangeCallback');
//console.log(response);
if (response.status === 'connected') {
// Logged into your app and Facebook.
LogUserIn();
} else if (response.status === 'not_authorized') {
//console.log('you must authorize the app');
alert(message);
} else {
//console.log('Please log into Facebook.');
}
});
}
From facebook documentation:
It's OK to ask a person once to grant your app permissions that they've declined. You should have a screen of education on why you think they should grant the permission to you and then re-ask. But if you use the method described in the [previous section)(#re-launching-permissions-dialog) the Login Dialog won't ask for that permission.
This is because once someone has declined a permission, the Login Dialog will not re-ask them for it unless you explicitly tell the dialog you're re-asking for a declined permission.
You do this by adding the auth_type: rerequest flag to your FB.login() call:
FB.login(
function(response) {
console.log(response);
},
{
scope: 'user_likes',
auth_type: 'rerequest'
}
);
Check out https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.0 and specifically the Re-asking for Declined Permissions section
In my site I test if a user is logged on Facebook in order to suggest him/her to like my Facebook site page.
Then, I use the conventional Facebook Js SDK function to understand if the user is logged or not:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
fbuid = response.authResponse.userID;
status = 'connected';
} else if (response.status === 'not_authorized') {
fbuid = null;
status = 'not_authorized';
} else { // the user isn't logged in to Facebook.
status = 'generic';
fbuid = 1;
}
that.evaluateFbStatus(status, fbuid);
}
It works perfectly with every browsers except Firefox.
In Firefox it returns always unknown even if the user is logged on Facebook and the status is not_authorized or connected.
Any help is accepted.
The problem is due to third party cookies.
To use Facebook SDK functions in Firefox, is necessary to open setting and able third party cookies Preferences > Privacy > Accept-third-party cookies
Have a look on this page for more details.
My application uses Facebook authentication:
FB.init({
appId: config.fbAppId,
status: true,
cookie: true,
// xfbml: true,
// channelURL : 'http://WWW.MYDOMAIN.COM/channel.html', // TODO
oauth : true
});
// later...
FB.login(function(response)
{
console.log(response);
console.log("authId: " + response.authResponse.userID);
gameSwf.setLoginFacebook(response.authResponse.accessToken);
}, {scope:'email,publish_actions,read_friendlists'});
And when using it, people can post to their wall:
var obj = {
method: 'feed',
link: linkUrl,
picture: pictureUrl,
name: title,
caption: "",
description: message
};
function callback(response) {
// console.log("Post on wall: " + response);
}
FB.ui(obj, callback);
This works fine, but there is one little hickup. If people:
Log in on the app.
Log out of Facebook.
Attempt to make a wall post from the app.
The opening of the wall post dialog fails. The console says "Refused to display document because display forbidden by X-Frame-Options.".
Can I instead get Facebook to show a login prompt to the user. Or can I detect the error and tell the user that he's no longer logged in on Facebook?
Just recall getLoginStatus BUT forcing a roundtrip to Facebook. Look following code:
FB.getLoginStatus(function(response) {
// some code
}, true);
Look the last parameter set to true to force the roundtrip.
From JS SDK documentation:
To improve the performance of your application, not every call to
check the status of the user will result in request to Facebook's
servers. Where possible, the response is cached. The first time in the
current browser session that FB.getLoginStatus is called, or the JS
SDK is init'd with status: true, the response object will be cached by
the SDK. Subsequent calls to FB.getLoginStatus will return data from
this cached response.
This can cause problems where the user has logged into (or out of)
Facebook since the last full session lookup, or if the user has
removed your application in their account settings.
To get around this, you call FB.getLoginStatus with the second
parameter set to true to force a roundtrip to Facebook - effectively
refreshing the cache of the response object.
(http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/)
What you could try and use is the FB.getLoginStatus where if the user is connected this would allow them to complete the wall post.
If they aren't connected then call the FB.login method before they can post on the wall.
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;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
There are also the events for login and logout that you can watch for and do something with those responses.
FB.Event.subscribe('auth.login', function(response) {
// do something with response
});
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
});
http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/