reasking for declined permissions in fb js sdk - javascript

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

Related

Is it possible to delete facebook permission, after login prompt?

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.

FB Login, jquery not working on chrome

My code looks as below
$(document).ready(function () {
$.getScript('//connect.facebook.net/en_UK/all.js', function () {
FB.init({
appId: 'XXXXXXXXXXXX',
channelUrl: '//localhost/channel.html',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
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
Dosomethinguseful();
} 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.
FB.login(function (response) {
if (response.session) {
dosomething();
}
});
}
});
});
});
Above code works great on safari and firefox. However, on chrome i dont see anything happening. Debugging shows no error.
Need help.
is there a working example of calling FB auth using jquery?
===========
tried the code from http://geekswithblogs.net/ptahiliani/archive/2013/08/23/facebook-login-authentication-example.aspx. It also doesnt work on chrome :(. I get following error
'Blocked a frame with origin "http://www.facebook.com" from accessing a frame with origin "https://s-static.ak.facebook.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.'
Maybe an old question but this happened to me recently.
We found when using a self signed certificate we would get a grey "broken" screen in facebook. However, when visiting the site directly (ie not via facebook) and we accept this illegit certificate THEN visited the facebook app it worked fine.
Seems Chrome won't ask you to continue if it detects an invalid cert when pulling in page resources via HTTPS. But it remembers if you accept one if requesting directly via HTTPS.
Good luck :)

FB.getLoginStatus() return "unknown" in Firefox when user is logged

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.

Get facebook app install timestamp

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.
}
});

How to detect user logging out of Facebook after logging into my app?

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/

Categories