The functionality that I need is to show a list of Facebook friends to the user on the website page with custom design, where the user can select some of them and send invites.
In API v2.0 it's possible to get a list of friends this way:
FB.api('/me/taggable_friends', function (response) {
...
});
But it doesn't return real users' ID that I need for invites with the next function call:
FB.ui({
method: 'apprequests',
message: invite_text,
to: 'user_id_1, user_id_2'
}, function (response) {
...
}
);
How can I get these real IDs?
Or how to resolve this functionality in another way? Because all the answers that I found were connected with games that don't fit me.
I need a full list of friends. Not just that already use my website (analog of the invitable_friends in-game section).
You are not allowed to use taggable_friends for inviting them, obviously it is for TAGGING friends and you only get a tagging token.
There is invitable_friends, but:
The invitable_friends API is only available for games that have a Facebook Canvas app implementation using version 2.0 of the Graph API.
(https://developers.facebook.com/docs/games/invitable-friends/v2.1)
I am afraid what you want to achieve is not possible. The proper way to invite friends to your website is to use the Send Dialog: https://developers.facebook.com/docs/sharing/reference/send-dialog
You can include one User ID in the "to" parameter. Of course it must be a User who authorized your App too, you can get those with /me/friends. Or better: Just open the Dialog and let the User select on his own.
Related
I want to send friend request from my app to any facebook user (who is not my friend but I have his app-scoped-facebook id.)
(Just kind of adding 'Add Friend' button in my app)
Is there any way to implement this in facebook API 2.0 and above
Adding friends is not possible through the API
You can call http://www.facebook.com/addfriend.php?id=[USER UID]
Where [USER UID] is a valid facebook user id.
I got one solution but don't know it will be deprecated or not as it is of v1.0
But at present its working :)
FB.ui(
{
method: 'friends',
id: fbid
},
function(data){
console.log(data);
}
);
I'm using the following Javascript for my users to send requests to "invitable friends" from my Facebook app:
FB.ui({
method: 'apprequests',
message: 'Come play with me etc.',
to: str_ids
},
requestCallback
);
function requestCallback(response){
if(response){
console.log(response);
}
else{
//show error to user
}
}
Where str_ids is a string containing the IDs returned by the invitable friends API. This all works fine.
When I invite a single user, let's say his Facebook ID is 1593894704165626, I get the following response:
request
"1399842883640198"
to
["1593894704165626"]
So here I have a unique request ID and the invited person's Facebook ID. I can now store this data in my database along with the inviter's ID, so I have all the necessary info.
However, now I want to reward the inviter after the invitee accepts the invitation and I'm running into a problem.
If user A and user B both invited user C, then when user C joins the game, how do I know whether to reward A or B?
I see from this question that it's possible to pass another parameter along with the invitation, which should help identify the inviter:
Facebook tracking who Invited whom
The first answer here suggests that you can pass such a custom parameter, but doesn't say how. Facebook's convoluted documentation is driving me insane.
Another thing - even if I send that additional parameter, I think there's a problem - for new users the app redirects to the Facebook page that checks whether they want to allow access to the app, and by the time they're redirected back to the app, the additional parameter will be lost.
Is there any solution to this?
Bit of an odd one: I've created an app that uses a jQuery AJAX request to query the Graph API and access a list of a given user's Likes (someone on my Friends list). I can use this within my app, and I get the same result as if I'd run the query through the Developer tools Graph API Explorer site (https://developers.facebook.com/tools/explorer).
The fun begins when people on the Testers list for the app (which is sandboxed) perform exactly the same actions, with the same friend (who isn't on the testers list); they don't receive any data back from the Graph API at all.
The testers have granted my app all the same permissions as I have, so why would we be getting different results?
Finally - I think I've found the solution.
By switching the Facebook JavaScript SDK file to a direct link rather than an asynchronous download, and calling the FB.login function with extra permissions defined in the scope later down the page:
FB.login(function (response) {
if (response.authResponse) {
// init app here
} else {
// cancelled
}
}, { scope: 'user_likes,friends_likes' });
... the testers are able to access their friends' Likes. Phew!
If there any way to check in PHP SDK if user can write on specific friend's Wall?
Example:
if ($facebook_can_write_to->'123456789') echo "You can write on this friend's Wall";
Using the FQL table (http://developers.facebook.com/docs/reference/fql/user/) you can check to see if the current user can post to a friends wall by loading up the friend's user information specifically the can_post field.
can_post bool Whether or not the viewer can post to the user's Wall.
According to the documentation you can post on a user friends wall if that user granted you the *publish_stream* permission:
publish_stream
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends.
There are some cases in which you won't be able to do so, for example if some user blocked your application then I guess it will fail if you try, so you should just check the response you get back from facebook for the api request and see if it worked or not.
Edit
As far as I'm aware you can not ask the api (nor via fql) "can my application post to this users wall", you can only ask "have this user granted my application the publish_stream permission".
If I understand what you want, I might have kind of a solution for you though.
I say show the user the option to post on a friends wall.
When the user chooses this option try to post on the friends wall (and I assume you are using ajax for that call), if it fails return some kind of code, then in the client side check for that code, if it returns use the javascript sdk to open a dialog.
You have two choices for dialogs, you can use the Feed Dialog like this:
var obj = {
method: 'feed',
to: "FRIEND_ID",
name: 'A message',
caption: 'Just trying something',
description: 'This is how to post on a friends wall'
};
FB.ui(obj, function(response) { console.log(response); });
Or you can use the Send Dialog:
FB.ui({
method: 'send',
to: "FRIEND_ID",
name: 'A message',
link: 'LINK_URL',
});
With this one though you have to post a link, I'm not sure if that works for you. After you tried and failed for a user you can save that data and use it later.
I want to get the statistics of all the pages associated with my account on facebook, i have the code to get the statistics of a page, i just want to get the page id of all the pages associated with my account, how can i do this?
Please help.
Thanks.
You'll need to request the manage_pages permission (more details here), once you have the aquired the permission, all you have to do is make a request to :
https://graph.facebook.com/YOUR_FACEBOOK_ID/accounts.
The return value will be a JSON with all the pages/applications that are associated with your account.
You can also use this great tool that facebook provides - The Graph API Explorer (/me/accounts) to explore what other information you can retrieve without having to write a single line of code :P very useful.
FB.api('/me/accounts', function(response) {
for (id in response.data)
{
page = data[id];
page.id;
page.name;
}
});
You can use Javascript API to do this, read more :http://developers.facebook.com/docs/reference/javascript/