FB.api wallpost link URL changes when it contains Facebooks TLD - facebook

Hi Im using this script to post:
postToFb:function () {
//alert(window.FbPostParameters.link);
FB.api('/me/feed', 'post', window.FbPostParameters, function (response) {
if (!response || response.error) {
console.log('/me/feed - Error occured');
} else {
console.log('/me/feed - Published to stream!');
}
});
},
And alerted window.FbPostParameters.link is:
http://www.facebook.com/FBPAGENAME/app_APPID?app_data=forum
Its funny, cuz when I checked the wallpost the url has become this:
http://www.facebook.com/FBPAGENAME?ref=hl&sk=app_APPID%26app_data%3Dforum
The problem is that the posted url is fully functional (and fb passes app_data to application) but the latter one is not working. Not even renders the application tab until I remove the %26app_data%3Dforum part.
I could not find any resource to debug this problem. Can you help me?
ps: encodeURI or encodeURIcomponent results the same.
UPDATE: link to example: http://www.facebook.com/kenivajszmuller/app_238038449651632
Can anyone help? ty

Related

Not getting the name and other information of my friend who is also using the same app using facebook login

I am trying to fetch the information about my friends who are also logged in (or using) the app using facebook , for that i am using graph api . But i am not getting relevant information . Can anyone please help me out on that .
I went through the facebook developer docs and tried many option but it didn't helped .
//Request
FB.api(
"/{app-id}", // app-id for the application
{
"fields": "context.fields(friends_using_app)"
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Using this when i am trying to fetch the information i am getting output like this
Not getting the name and other information of my friend who is also using the same app using facebook login .
This would be the correct code to get all friends who authorized the App too:
FB.api('/me/friends', (response) => {
if (response && !response.error) {
/* handle the result */
}
}

Get the location id of a fan page

I have a fan page with an address.
Also, I can get the location details using the facebook API.
However, to create a new post with a review button I need the location id instead of the details.
I am using the following lines to create a share button:
var data = {
message: 'Hi !',
place: location_id
};
FB.api('/me/feed', 'post', data, function(response) {
if (!response || response.error) {
console.error(response.error);
} else {
console.log(response.id);
}
});
And it works if I use a specific location id. But I can't get the location id from a specific page.
Please give me some ideas. Thank you!
I was falling asleep, but I got one idea.
And finally, that idea was the solution:
It is possible to use the fan page id directly in the place parameter. It can be used like a place id.

facebook api not returning email

I am trying to return user email address using facebook api. Few days ago it was working fine, but today stopped working, and don't know why.
So first I get access token:
FB.login(response => {
if (response.authResponse) {
resolve(response.authResponse.accessToken);
} else {
reject({
error: 'User cancelled login or did not fully authorize.'
});
}
}, {
scope: 'public_profile,email'
});
then I try to get user data
FB.api('/me', {fields: 'first_name,last_name,email'}, function(response) {
console.log(response);
});
but I only get data for first_name and last_name. There is no email.
Also when I ask for permissions, it gives me email as granted, but as I said, email is not returned.
FB.api('/me/permissions', function(response) {
console.log(response);
});
Does anyone knows what can be the problem?
BTW: I am using API v2.4.
FB.api('/me?fields=email,name', function(response) { /* stuff here */ });
Try adding your return fields to your request.
I know this is old question however if someone still seraching for answers then following workaround worked for me.
You need to add email in scope scope="public_profile,email".
<fb:login-button scope="public_profile,email" autologoutlink="false" onlogin="OnRequestPermission();"></fb:login-button>
A possible cause is that the user did not validate the email. Try with another user with validated email to make sure this is not the problem.
See also this answer
If you set all code correctly and still don't get an email from API. The user probably doesn't have an email bound to the account or the email not confirmed by the user.
I made it work using a promise and adding {scope:'email'} to the initial request then including 'email' in the fb.api fields.
fb.login({scope:'email'}).then(function (resp) {
if (resp.status === 'connected') {
fb.api('/me', 'get', {fields:'id,email,first_name,gender,...'}).then(function (FbUserData) {
console.log(FbUserData);
});
}
});
I spent a lot of time trying to figure out why the email is not returned on the FacebookLoginASPnetWebForms Asp.Net application (https://github.com/nickpinheiro/FacebookLoginASPnetWebForms).
I got it working, thanks to N Nem's post above (thanks!).
Open Default.aspx.cs
In HyperLink1.NaviagteUrl, add the query string parameter: &scope=public_profile,email
HyperLink1.NavigateUrl = "https://www.facebook.com/v2.4/dialog/oauth/?client_id=" + ConfigurationManager.AppSettings["FacebookAppId"] + "&redirect_uri=http://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/account/user.aspx&response_type=code&state=1&scope=public_profile,email";
I also had to fix some bugs to parse the access token correctly.
This time, the email address is available! I hope this helps?
N Nem above fixed for me. Had the code correct, but missing the scope on the login button. Code I use is below.
function statusChangeCallback(response){
if(response.status === 'connected'){
registerUser(response);
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
function registerUser(statusResponse){
let userId = statusResponse.authResponse.userID;
FB.api('/'+userId+'/?fields=id,email,first_name,last_name',function(response){
if(response && !response.error){
console.log(response);
}
});
}
This is kinda old post but I am sharing the solution that worked for me.
FB Login SDK version: v6.0
First, make sure that the user (which is you for testing purposes) has a valid/verified email. Refer to the code below.
FB.login(response => {
// your code
}, {
scope: 'public_profile,email',
return_scopes: true,
auth_type: 'rerequest'
});
And in getting the user details
const response = await axios({
method: 'get',
url: 'https://graph.facebook.com/v6.0/me?fields=id,name,email&access_token=ACCESS_TOKEN&pretty=0&sdk=joey&suppress_http_code=1'
});
I've added the parameter fields=id,name,email

Facebook Graph API Posting a Comment as User

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!

Check if current user (session) is fan of my page or not

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!