Facebook Users logging fine but not showing up in api requests - javascript

I have an Android and Web app that uses the Parse backend with FB login. I just created the Web version and I'm having an issue with my users that log in through web. They are being saved to the backend just fine along with their FB info, but for some reason, when I make a me/friends api request, I cannot find any of my friends that have logged in through my website (anyone that logged in through the Android app shows up just fine). This leads me to believe that even though the Parse login worked fine, there is probably an issue with FB login. My code is exactly as the parse docs describe:
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
FB.api('/me', function(response) {
var currentUser = Parse.User.current();
if (currentUser) {
currentUser.set("fbName", response.name);
currentUser.set("facebookId", response.id);
currentUser.save();
window.location = "index.html";
} else {
alert("Login Did Not Work!");
}
});
} else {
FB.api('/me', function(response) {
Parse.User.current().set("fbName", response.name);
Parse.User.current().set("facebookId", response.id);
Parse.User.current().save();
window.location = "index.html";
});
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
Is there something else I should be doing here?

If anyone is having the same problem, I simply forgot to include the user_friends permission (or any permission for that matter, but user_friends is what I wanted).

Related

FB.getLoginStatus return authResponse null even after user login through Facebook login dialog

FB.getLoginStatus return authResponse as null, im unable to determine if i need to open the login dialog again. when user is prompt with login dialog again the previous permission is being reseted. For example, when user agree to allow app to manage a particular page. When login dialog is prompt again, they are unable to see the page that is previous approve for manage_pages permission. Re-login revoke the permission to manage that particular pages.
What can i do to prevent Facebook to prompt login dialog again? I am using v3.3 for facebook login:
checkLoginState(){
var self = this;
window.FB.getLoginStatus(function(response) {
console.log( 'login status' + JSON.stringify(response));
if(response.authResponse === null){
self.showLogin();
}
}, true);
}
showLogin(){
var self = this;
// //fb permission scope and login function
window.FB.login(function(response){
console.log('has access token', response.authResponse)
if (response.authResponse) {
console.log('has access token' + response.authResponse.accessToken);
self.setState({
fb_access_token: response.authResponse.accessToken
})
console.log('self.state', self.state)
self.storeFBToken();
self.retrieveFbProfile();
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'public_profile, manage_pages, email, pages_messaging, pages_show_list'});
}
I just tried with a production facebook app id and test it on a https page. getLoginStatus is returning access token correctly. it is still unknown to me why getLoginStatus does not work with a development facebook app id on localhost.

How Does Facebook SDK Login Work?

If there is a github repo with the unminified source that would also work as an answer.
https://connect.facebook.net/en_US/sdk.js
I'm new to oAuth in general but my assumption was that there was no way to get the auth token from an opened window. But in there example they show something like this-
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
When testing in Plunkr, this opened a new window, I logged in, no redirect occurred, but I was able to use the auth token. I wanted to investigate how they did this but wasn't able to find the source.
Does anyone know how they passed the token from the opened window back to the original window?

Facebook login silently failing

I'm trying to implement login to a website with Facebook, using their JavaScript SDK. I understand that this is OAuth 2 under the hood, although that shouldn't even matter... I am setting things up using the async loader, and the FB variable exists and I can call functions in it. When I call FB.login(), another tab opens, flashes for a fraction of a second, and then closes. I then wind up back on my page, with no events having been triggered and no sign that anything has happened.
I have initialized the API as follows:
FB.init({
appId : facebookAppID,
channelUrl : channelFilePath,
status : true,
xfbml : true
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
console.log("Connected.");
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else if (response.status === 'not_authorized') {
console.log("Not logged in.");
} else {
console.log("Still not logged in.");
}
});
Then my login call is simply:
function loginFacebook() {
console.log("Trying to log in.");
FB.login();
}
One detail which might be relevant is that I'm running for development purposes on a nonstandard port, 1980 instead of 80. It's not easy for me to try port 80, because of where I'm running, but if it turns out to be the problem I absolutely can.
Thanks in advance. :)
It turned out to be the port. Yes - they check, apparently! The completely silent failure was really perplexing...

Posting to page wall as admin by Graph Api requires manage_pages permission too

One of my client's website, i coded so that user's of his page can post from his website using Graph Api.Posting is done this way -
FB.login(function(response) {
if (response.status=='connected') {
if (response.authResponse.accessToken)
{
var token = response.authResponse.accessToken;
FB.api('/'+jQuery("#input_id_storing_pageid").val()+'/feed?access_token='+token+'&message='+jQuery("#message_input_box").val(), 'POST', function(response) {
if (!response || response.error) {
alert('Error: You are not allowed to post '+ response.error.message);
} else { /*do other tasks */ }
});
} else { /* show alert messages */ }
} else { /* show alert messages */ }
}, {scope:'publish_stream' });
It was posting well before but now page admin can't post, getting error-
"(#283) Requires extended permission: manage_pages OAuthException".
Any non-admin user posting going well, but not by some page admin users who have manager role for the page. I tested using graph api explorer but same error I am getting.
Fyi the application by which posting done by graph api has October 2013 migration enabled, but I don't think it has this new requirement that page admin need to have manage_pages permission as well as publish_stream permission to post to page wall, cause I asked client to disable that setting for testing. So where went wrong?

Authorize Timeline app to user's profile and then do OpenGraph action

I'm pretty new to Facebook development, so been trying to read up on older questions but still a bit lost =\
Here's one that I'm struggling with:
Currently I have an app with several defined Open Graph actions i.e. "ask a question". Is there a way to provide a dialog box for users that do not have the app yet, so that after they authorize the app, it'll go ahead and do the OG action? Ideally, it'd happen smoothly and without multiple dialog boxes.
OG action:
FB.api(
"/me/beta_sandbox:ask?question=http://example/question/1",
'post',
function(response) {
if (!response || response.error) {
alert('Sorry, your question was not shared: '+response.error);
} else {
alert('Your question was successfully shared!');
}
});
Solution: redirect uri?
Any help would be greatly appreciated =)
You should authorize users prior to publishing an action.
You can nest the publishing of an action within FB.getLoginStatus method to publish action for logged in users and bring login dialog for user who not connected with app or logged out of Facebook:
var publishAction = function(){
FB.api('/me/beta_sandbox:ask?question=http://example/question/1', 'post',
function(response) {
if (!response || response.error) {
console.log('question was not shared', response);
} else {
console.log('question was successfully shared!');
}
}
);
}
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// User is authenticated, Publish Action
publishAction();
} else {
// Bring Login Dialog to authenticate the user
}
}
You also may leverage FB.login method to publish action after user is logged in (for users who already logged in dialog will not be opened and closed immediately and callback will be called):
FB.login(function(response) {
if (response.authResponse) {
// User is authenticated, Publish Action
publishAction();
} else {
// User declined authentication
}
});

Categories

Resources