Facebook Fb.ui select only one friend - facebook

I am building a small board game for Facebook, and I need a way to send an app request to only one friend. I will use
FB.ui({method: 'apprequests', to: '1234', message: 'A request especially for one person.', data: 'tracking information for the user'});
But I need a way for the user to select a friend an only one from his list. Is there a way to pop the friend-selector and restrict the maximum selection to 1?

Use "max_recipients" parameter
FB.ui(
{
method : 'apprequests',
message : 'A request especially for one person.',
to: '1234',
max_recipients:1,
data: 'tracking information for the user'
}
);

You could build your own similar widget that lists all of a users friends using the graph api to retrieve all of their friends by calling /me/friends. Then let the user select a friend and clicking some kind of invite button next to the friend that calls this:
FB.ui({method: 'apprequests', to: '4', message: 'A request especially for one person.', data: 'tracking information for the user'});
And just set the 'to' parameter to the one user selected.

Related

how to post on multiple facebook friends wall using Facebook api FB.UI

how can post on my facebook friends wall using FB.UI
my code is
FB.ui({
method: 'feed',
link: 'https://developers.facebook.com/docs/',
to:['405631902932995,626150064162274'],
caption: 'An example caption'
}, function (response) {
console.log(response);
});
i am getting error like
API Error Code: 100
API Error Description: Invalid parameter
Error Message: ["100004585663846,100003018593104"] does not resolve to a valid user ID
That parameter only allows to enter one ID, not an array of them. Meaning, what you want to achieve is not possible at all, you can only specify one friend.
https://developers.facebook.com/docs/sharing/reference/feed-dialog/
You can also use the Send Dialog to send a message to a friend: https://developers.facebook.com/docs/sharing/reference/send-dialog
The same applies to the "to" parameter, you can only specify one recipient.

Check if user can write on a friend's Wall

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.

Facebook Multiple invites using Requests 2.0

Is it possible to send multiple invites using new Requests 2.0? Documentation as of now saing that 'to' parameter can specify only one user, so it single user or standart request dialog even without possibility to set default filter! It's huge drawback from hidious by nature, but effective in purpose FBML.
Sure.
Look in the docs for Requests 2.0:
Send to Many
From your application front-end,
execute:
FB.ui({method: 'apprequests', message: 'You should learn more about this awesome game.', data: 'tracking data: 'tracking information for the user'});
This will open the facebook Dialog:
If you meant in your question whether or not you can filter multiple id's - meaning, you choose the list of uid's to send the request to and not the user - then the answer is no, it's not possible currently.
Of course.
FB.ui({
method: 'apprequests',
message: 'text for the receiving user',
data: '127', // to know what to do with it.
title: 'title of window.'
});
see this fanpage for an example:
http://www.facebook.com/NeonFashion?sk=app_176086155780033
or i missunderstand your questions and you actual looking for something like
Facebook requests 2.0 filter
It is (now?) possible to open a request dialog targeting multiple users at once, by passing an array of ids in the "to" field.
See the "sendRequestToManyRecipients" example in https://developers.facebook.com/docs/reference/dialogs/requests/

Facebook API: Suggest page to friends and view which are were selected

I am developing an application which is based on user challenges. The app also requires a Facebook account to play.
I want a user to be able to select a bunch of friends he wants to challenge and send them an "invitation". But besides this, I need to find which friends did the user invite in order to save them to my database and "prepare" the challenge.
I managed to do the select-friends-dialog using this, but have no idea how to retrieve the selected users. Also, does this work on non-canvas Facebook applications? As I read that page, I am not sure whether it will work for my non-canvas application.
Here is my select-friends-dialog code:
function challengeFriends(){
FB.ui({
method: 'apprequests',
message: 'message",
title: 'title'
});
}
Any help is highly appreciated! Thank you.
I've written a tutorial that covers what you are asking for and other aspects of the Request dialog: How To: Send An Application Request Using The Facebook Graph API
The idea is to capture the request ids from the callback and save them in your DB, and within the request itself you can find the invitee id (friend id):
FB.ui({
method: 'apprequests',
message: 'Check out this application!',
title: 'Send your friends an application request',
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
$.post('handle_requests.php',{uid: <?php echo $uid; ?>, request_ids: requests},function(resp) {
});
} else {
alert('canceled');
}
});

FB Connect - Can It Be Used to share message with multiple users?

I suppose the answer is pretty simple, but i cant find conclusive answer either way.
Is it possible to use facebook to log in a user, fetch their friends, allow them to select them and then post to their profiles in turn, even if that means firing up a custom modal with html to select from the list of users friends before passing the IDs on to the publishStream function in a loop.
Any response would be dandy. Thanks guys and gals.
If you post to the logged-in user's stream, you have no control over which friends see it in their own streams.
Alternatively, you can send facebook notifications to friends that were selected, subject to the daily notification limit imposed on your app by facebook. Be aware that facebook is phasing out noficiations.
You can do exactly what you said. Just get the list of user IDs before hand using your custom dialog you mentioned. Then call the FB.ui function repeatedly, populating the "to" parameter with each friend ID.
FB.ui(
{
method: 'feed',
to: #,
name: 'name of post',
link: 'http://link.com',
picture: 'http://link.com/image.jpg',
description: 'descriptive text',
},
function(response) {
if (response && response.post_id) {
alert('Post was published.'+response);
} else {
alert('Post was not published.'+response);
}
}
);