Facebook Login API data-scope permission didn't work? - javascript

My code as below, and it's will display Facebook login button, and send permission request for "public_profile, user_groups, publish_actions".
but after user logined, always only has "public_profile", other's setting are missing.
May I know, are there anything I missing?
HTML Code
<div class="fb-login-button
align-right"
data-max-rows="1"
data-size="medium"
data-show-faces="false"
onlogin="MyFBLogin()"
data-auto-logout-link="false"
data-scope="public_profile, user_groups"></div>
Javascript Code
$(function () {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/zh_TW/all.js', function () {
FB.init({
appId: 'xxxxxxx',
xfbml: true, // parse XFBML
version: 'v2.0'
});
$('#loginbutton,#feedbutton').removeAttr('disabled');
});
});
function MyFBLogin(){
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
//Logined
}
else {
//Not logined
}
});
}
PS: the permission setting is work when I using my app develop account, but other's account didn't work.

If your app asks for more than than "public_profile", "email" and "user_friends" permissions it will require review by Facebook before your app can be used by people other than the app's developers.
While facebook accept your review submit, only de developers of the app can do all the actions on the app flow.
Documentation for review

Related

Parse Facebook Login Error: "You must initialize FacebookUtils before calling logIn"

I am trying to use Facebook login on Parse with cordova.
$cordovaFacebook.login(['email'], function(response) {
Parse.FacebookUtils.logIn('email', {
success: function(user) {
console.log('success fb login')
// Handle successful login
},
error: function(user, error) {
// Handle errors and cancellation
console.error(error)
}
});
}, function(error) {
console.error(error)
});
And in a .run block on app.js, I have
window.fbAsyncInit = function () {
Parse.FacebookUtils.init({
appId: fbAppId,
autoLogAppEvents: true,
xfbml: true,
status: true,
cookie: true,
version: 'v2.4'
});
FB.AppEvents.logPageView();
console.log('Parse FB loaded')
// loadParse()
};
However, on the logger when I run the app on my iOS device, I never see a "Parse FB loaded". When I run it on a browser, I do see the "Parse FB Loaded".
Whenever I try to login via Facebook on my device, I get the error You must initialize FacebookUtils before calling logIn.
I believe the issue is that Parse is not initing FacebookUtils when on a device, but it is on the browser. Why would this be? Would it be an issue with the window object?
Note that the Facebook login itself is working (through the whole FB login flow), but after the callback to login via Parse with FacebookUtils, I receive the described error.
Thanks for your help!
try this... before to FacebookUtils
parse.initialize('APPLICATION_ID', 'JAVASCRIPT_KEY');
parse.serverURL = 'https://parseapi.back4app.com/';
parse.FacebookUtils.init({ // this line replaces FB.init({
appId : 'xxxxxxx', // Facebook App ID
status : true, // check Facebook Login status
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true, // initialize Facebook social plugins on the page
version : 'v2.12'//point to the latest Facebook Graph API version
});

Notification not sending to facebook friend

I have created an application where i am trying to invite friends via facebook invite friends js method but all working fine but no notification sent to that friend.
My Application Link: http://www.huzoorbux.com/fl/app/android/www/homepage_nopost.html
My Code:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.api(
"/me/invitable_friends",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
if(top.location != self.location) {
top.location = self.location
}
FB.init({
appId:'228877127299395',
cookie:true,
status:true,
xfbml:true
});
function FacebookInviteFriends()
{
FB.ui({
method: 'apprequests',
message: 'Join My Job Buddy'
});
}
</script>
<div class="connectbutton5" id="ol">Invite Friends</div>
App Requests are for games only, that may be the reason. And always use a callback function for error handling, maybe you are missing an error:
FB.ui({method: 'apprequests',
message: 'YOUR_MESSAGE_HERE'
}, function(response){
console.log(response);
});
Also:
The invitable_friends API is only available for games that have a Facebook Canvas app implementation using version 2.0 of the Graph API.
Source: https://developers.facebook.com/docs/games/invitable-friends/v2.1
If you want to invite someone to a website, use the Send and Share Dialogs and Buttons. You donĀ“t even need to authorize the user for them.

publish_actions in scope not triggering second dialog

I have the following javascript code to login to my website using facebook
FB.login(function(response) {
if (response.authResponse) {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
//proceed to login
} else {
//login failed
}
}, {scope: 'publish_actions, email, user_birthday',
appId : 'myAppId',
cookie : true});
The first dialog shows up fine requesting their email and birthday. However, the second (optional) dialog does not show up requesting to post to their profile. I have seen this on many sites, but it does not show up on mine.
Is there any other steps I need to take to show this? I have tried publish_stream as well.
EDIT: Still no answer. I am testing with a Facebook account that was previously connected, but I removed the app from my Facebook profile and connected again. That should ensure that the second dialog comes up, but it doesn't.
I once read in the facebook documentation you must request this permission in the init function.
try
window.fbAsyncInit = function () {
FB.init({
appId: 'Id_App',
status: true,
xfbml: true
}), { scope: 'publish_actions' };
};

FB.getLoginStatus doesn't work in Chrome even sandbox disable

I follow railscast to add "sign in with Facebook" feature in my site, there is no problem to login. But when try to logout, it seems that FB.getLoginStatus never got fire even when I disable Sandbox Mode in facebook developer app settings (as suggested in some other discussion):
(function() {
jQuery(function() {
$('body').prepend('<div id="fb-root"></div>');
return $.ajax({
url: "" + window.location.protocol + "//connect.facebook.net/en_US/all.js",
dataType: 'script',
cache: true
});
});
window.fbAsyncInit = function() {
FB.init({
appId: 'xxxxxomittedxxxxx',
cookie: true,
status: true,
xfbml: true,
oauth: true
});
$('#sign_in').click(function(e) {
e.preventDefault();
return FB.login(function(response) {
if (response.authResponse) {
return window.location = '/auth/facebook/callback';
}
});
});
return $('#sign_out').click(function(e) {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
return FB.logout(response.authResponse);
}
});
return true;
});
};
}).call(this);
The reason I know the FB.getLoginStatus never get in (or doesn't work) is I replace the body with:
FB.getLoginStatus(function(response) {
return alert("I am here!");
});
and I cannot see my alert while "sign_out" click.
I am running both Chrome and Firefox having the same behaviour. Could anybody help to spot what am I missing? Thanks a lot.
Let me describe more specific about the "behaviour" I encountered:
sign in with Facebook from mysite.com the first time a Facebook login window will popup and ask for email and password, and I can sign in to my site perfectly ok and work as expected
then I click on sign_out button from mysite.com/users/1, it looks like it sign out ok.
then sign in with Facebook from mysite.com again, now it won't popup the Facebook login window anymore and login to mysite.com/users/1 directly without asking email and password!
if I open another browser window and go to facebook.com and logout from there, then when I sign in with Facebook from mysite.com, it will popup a Facebook login window now and ask for my email and password.
I would like my site to behave: "when logout from mysite.com/users/n and sign in with Facebook again from mysite.com, the Facebook login window shall popup"
Anyone could be of help? Thanks a lot.
EDIT:
Further investigation found the "root" cause might be still: the sign out is under the different route (or page) of the sign in route and FB.getLoginStatus just cannot be fire under the mysite.com/signout. The error message from firebug indicates that "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."
To proof it is the route issue, I put a sign out link in the same route (page) as sign in route which is the root route mysite.com as specified in the "Website with Facebook Login", everything works and can logout as expected:
<%= link_to "sign out facebook", "#" , id: "sign_out" %>
by the way the sign_out js is revised to get rid of FB.logout(response.authResponse) uncaught [object Object] error, because FB.logout expects function as parameter:
return $('#sign_out').click(function(e) {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
FB.logout();
}
}, true);
});
};
So, the bottom line: FB.getLoginStatus might still have a bug which cannot handle the call from a different route than sign in route. (I tested with Chrome, Firefox and Safari and all behave the same but not true for IE10. Somehow IE10 works even sign out at different route.)
Any comment from people who have similar problem? Please advise. Thank you very much in advance.
Try adding true as second parameter to getLoginStatus, as stated in FB dev doc:
FB.getLoginStatus(function(response) {
// this will be called when the roundtrip to Facebook has completed
}, true);
This should avoid caching.
Another option is to subscribe to events:
FB.Event.subscribe('auth.login', function(response) {
// do something with response
});
All from here
Comment if you have questions.
EDIT:
I modified your script a little bit, removed unneeded code parts. You had too many returns that are not needed. I tried sign out within this modified script, it works as you need it.
Events subscription is for check purposes.
<head>
<title>Exam entry</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<input type="button" value="Sign in" id="sign_in" />
<input type="button" value="Sign out" id="sign_out" />
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: '586844044669652',
cookie: true,
status: true,
xfbml: true
});
// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
// for any authentication related change, such as login, logout or session refresh. This means that
// whenever someone who was previously logged out tries to log in again, the correct case below
// will be handled.
FB.Event.subscribe('auth.authResponseChange', function (response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected') {
// The response object is returned with a status field that lets the app know the current
// login status of the person. In this case, we're handling the situation where they
// have logged in to the app.
testAPI();
} /*else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app, so we call
// FB.login() to prompt them to do so.
// In real-life usage, you wouldn't want to immediately prompt someone to login
// like this, for two reasons:
// (1) JavaScript created popup windows are blocked by most browsers unless they
// result from direct interaction from people using the app (such as a mouse click)
// (2) it is a bad experience to be continually prompted to login upon page load.
FB.login();
} else {
// In this case, the person is not logged into Facebook, so we call the login()
// function to prompt them to do so. Note that at this stage there is no indication
// of whether they are logged into the app. If they aren't then they'll see the Login
// dialog right after they log in to Facebook.
// The same caveats as above apply to the FB.login() call here.
FB.login();
}*/
});
$('#sign_in').click(function (e) {
e.preventDefault();
FB.login(function (response) {
if (response.authResponse) {
//return window.location = '/auth/facebook/callback';
}
});
});
$('#sign_out').click(function (e) {
FB.logout(function (response) {
console.log("Here logout response", response);
});
});
};
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Good to see you, ' + response.name + '.');
});
}
// Load the SDK asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>

FB.Login response.session not working?

I'm having a problem with the following code. According to the JS, if the response.session is valid, it should alert("User is logged in!");. The problem is, I'm pretty sure the session is valid, but it alerts "User is not logged in!". I know the session is valid, as I have logged in before, and allowed the app publish_stream when the window appeared. I have also tried removing the app from my FB, but when I allow it again, it still alerts "User is not logged in!". What is wrong with my code?
<html>
<head>
<title>My Facebook Login Page</title>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '436956019655560',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
};
function fbLogin() {
FB.login(function(response) {
if (response.session) {
console.log("User is connected to the application.");
var accessToken = response.session.access_token;
alert("User is logged in!");
} else {
alert("User is not logged in!");
}
}, {scope:'publish_stream'});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<INPUT TYPE="BUTTON" ONCLICK="fbLogin()" value="login">
</body>
</html>
I'm pretty sure that response.session does not exist anymore. I believe you need to be looking for response.authResponse. Check out the docs on FB.login:
As of December 13th, 2011, the JavaScript SDK now only supports OAuth 2.0 for authentication. The ability to enable OAuth 2.0 in the JS SDK was first introduced in July. All apps were given until October 1, 2011 to test and migrate. With this change, please ensure that you replaced response.session with response.authResponse.
Try checking for response.authResponse instead. Also, try logging the response object to the console and see exactly what you are getting back.

Categories