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

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');
}
});

Related

The posts fo Feed method in FB.ui are not visible in Facebook timeline

I created an Application in facebook and used in my website.
In my page I am using this function to share a photo.
function postToFacebook(url, img) {
FB.ui({
method: 'feed',
link: url,
picture: img,
name: "Sample name",
description: 'sample desc'
}, function (response) {
console.log(response);
});
}
This function is working and sending a ShareLink on my Time line. But nobody can see my post. I just can see the post on my TimeLine !!!
What it is the problem?
I found out the problem myself.
it is because of the Status of Facebook Application.
Do this setting to fix the problem:
Go to Facebook Developer => You Application => Status & Review => set this option to YES:
"Do you want to make this app and all its live features available to the general public?"

deleting facebook requests

The facebook docs here say "it is the Developers' responsibility to delete a Request once it has been accepted". As far as I understand, when someone sends a request to multiple users on facebook like this:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'test message'
}, requestCallback);
}
only one request_id is returned via requestCallback() function.
Then, if I delete the request when someone accepts it, how would other users accept the deleted request?
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to delete the corresponding requests like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Check out the Request ID Format section of the FB request overview page.
The actual graph path for a request actually sent to specific user is "request-id"_"recipient-user-id".
you can access to facebook on mobile mode (m.faceook.com)
1-access the invitation panel
2-display all the invitations
3-open console mode in chrome
4-activate jquery by cpying and pasting all the jquery.min code into console
and excecute this script :
$("._54k8._56bs._56bt").trigger("click");
that will cancel or the invitation sent

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.

How can I redirect to my app page after accepted a app request sent from our app?

I have a issue for facebook apprequests (oauth2, graph)
I sent a app request to my friend B.
B logged into facebook and found our request in the app list.
B clicked the accept button
B redirected to the facebook canvas page. I want to rediect to our app, not facebook's canvas, is this doable?
thanks
you can put a url in the data param
see here http://developers.facebook.com/docs/reference/dialogs/requests/ under properties at bottom.
data Optional, additional data you may pass for tracking. This will
be stored as part of the request objects created.
This will get passed back to you and you can use javascript to location.href to the url in the data.
----------Here is a sample i have used in the past
var thisimg = 'AN_IMG';
var thisurl = 'A_URL';
window.sendrequest = function(){
FB.ui({ method: 'apprequests',
title: 'A request.',
message: 'Rate Me! Request from: ' +thisname+' ',
data: ''+thisimg+' '+thisurl+' ',
filters: ['all'],
});
}
---------- Sample from Facebook with data param added.
var thisimg = 'AN_IMG';
var thisurl = 'A_URL';
function sendRequestToManyRecipients() {
FB.ui({method: 'apprequests',
message: 'My Great Request',
data: ''+thisimg+' '+thisurl+' ',
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
upon callback you can do a window.top.location.href=''; with the url you passed in data.
NOTE: The default redirect for a request is the canvas, this cannot be changed. After user lands on your canvas you will read the data param from the request and redirect them to your external app.
"i do not see any other way to do this, since requests2.0 does not include option for a redirect uri."
As you have already included Facebook javascript SDK in your App and you have writen this code for inviting friend for your App in a script
FB.ui({ method: 'apprequests', redirect_uri: 'APP URL',
message: 'My Message' });
This will redirect to App URL without redirecting to Facebook canvas URL.So this will not work even if you use data parameter such as
FB.ui({ method: 'apprequests', data: 'APP URL',
message: 'My Message' });
Write this code at your App landing page i.e. in index.php
$requestid=$_GET[request_ids];
if(!empty($requestid)) {
echo "<script> window.top.location.href='APP URL'; </script>";
}
This is an old question, but now there is a simpler solution.
In the Facebook app settings under "Facebook Canvas" there is a field titled "Mobile Site URL". When a user tries to open your canvas app from a mobile device (s)he will be redirected to that URL.
That URL should point to a page from which you should redirect to the App Store or Play Store (or coming soon page) based on the browser user agent.

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);
}
}
);