I use default facebook dialog to ask for request
<script type="text/javascript">
function sendRequestToRandomFriends() {
FB.ui({method: 'apprequests',
message: '<?= na ('request text') ?>',
to: '<? $to = '';
foreach ($Rfriends as $c) {
if (isset($c['uid'])) $to .= $c['uid'] . ',';
}
if (!empty($to)) echo substr($to, 0, -1); ?>'
}, requestCallback);
}
But I saw many self created dialog windows , which ask to send requests.
How they sends requests when user press the button ?
I found your answer. It is buried deep down in the documentation. To send a user request without the FB.ui dialog you can use the grpah api's create user request to send.
Create
You can post a apprequest for a user by issuing an HTTP POST request
to /USER_ID/apprequests with the app access_token.
Note: POSTing to the Graph API endpoint of /USER_ID/apprequests is
considered an App to User Request. App-Generated Requests do not
receive notifications and get limited distribution in comparison to
User to User Requests sent with the Request Dialog
Related
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
i am using facebook apprequests to inviting friends as below
function invitefriends()
{
FB.init({
appId:'XXXXXXX', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'apprequests',
message: 'Here is a new Requests dialog...'});
}
</script>
But how get friend id once he accept the request i am able to get below when user accept request
https://apps.facebook.com/XXXXXX/?request_ids=XXXXXXX&ref=notif&app_request_type=user_to_user¬if_t=app_request
from above i can get from userid but how to get userid who accept request
i tried to pass request_ids with redirect_uri but once user install application it get disappeared.
Looking at the Requests documentation, whenever a user uses your app to send a request, they are redirect post-send to your app with ?request=REQUEST_ID&to=ARRAY_OF_USER_IDS appended to the redirect_uri.
So, once you should setup your redirect URI to capture the request ID and the UID array and store it for later.
Then, when the user who received the request accepts it, they'll be directed to a URL similar to the following:
https://apps.facebook.com/APPNAME/?request_ids=REQUEST_ID&ref=notif&app_request_type=user_to_user¬if_t=app_request
You can then compare the request_id received here to the request ID you've already stored and then once the user has accepted and dropped onto your App, you'll receive a signed request which you can parse to retrieve their User ID.
I'm using the javascript SDK to fire the send method of fb.ui. It works if I'm logged in as myself and send the messages to other developers on my team. When I log on as a test user and send to another test user, there is no error but the receiver never gets the message.
Code below shows click event from my button:
$(".invite_fb_friends").click(function() {
<?php
$subject = __("Please check out Volved", "volved", "volved");
if (isset($current_user->volved_cause)) {
$p = get_post($current_user->volved_cause);
$invite_id = get_user_personal_invite();
$description = sprintf(__("Follow this link and join me in supporting %s, or a cause of your choice!"),
$p->post_title);
$link = site_url("/cause/". $p->post_name . "/?invite_id=" . $invite_id);
$picture = get_bloginfo('template_directory'). '/images/cause_images/' . $p->post_name . '/logo.jpg';
} else {
//No cause chosen
$description = __("If you follow this link, you'll learn about Volved. If you like, sign up and start making a difference.");
$link = site_url("/");
$picture = get_bloginfo('template_directory') . '/images/logo64.png';
}
//call below documented at: https://developers.facebook.com/docs/reference/dialogs/send/
?>
res = FB.ui({
method: 'send',
name: '<?php echo $subject; ?>',
link: '<?php echo $link; ?>',
//picture: '<?php echo $picture; ?>', //Does not seem to work with valid URL. HTML shows URL but no pic displayed. Leaving blank shows picture of sender
//redirect_uri: filling this in creates an error on facebook
description: '<?php echo $description; ?>'
});
});
Test users can only send messages to other test users. If your other user is a real user, your own account for example, it will not send.
From Facebook:
https://developers.facebook.com/docs/test_users/
Limitations
We ensure that test users are exempt from Facebook spam or fake
account detection systems to ensure that you can test your app without
worrying about getting disabled.
Also, to ensure that using test user accounts to test various
scenarios doesn't end up unintentionally creating spam, we enforce
certain limitations on what test users can do.
Test users can interact with other test users only and not with real
users on site. Test users cannot fan a public Page or create public
content on them like writing on a Page's wall. A Test user can however
view and interact with the app tab on the Page if they are associated
with that app. They can be accessed and used by any developer of the
associated app. They only have test privileges on the associated app.
This implies that they can use the app in live mode or sandbox mode
but cannot edit any technical settings or access insights for that
app. A test user is always a test user and cannot be converted to a
normal user account.
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.
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');
}
});