I'm having trouble getting users to forward the App request to his friends;
I'm using the next code in client-side:
window.fbAsyncInit = function() {
FB.init({
appId: 'FBAPPD',
frictionlessRequests: true,
status : true,
cookie : true,
xfbml : true
});
};
When the users selects her friends:
function sendRequestToRecipients() {
var user_ids = document.getElementById("request_ids").value; //ID_user1,ID_user2...
FB.ui({
method: 'apprequests',
message: 'Prueba una nueva forma de comunicarte con tus contactos...',
to: '' + user_ids + '',
}, requestCallback);
function requestCallback(response) {
// Handle callback here
if (response.request && response.to)
{
var request_ids = [];
for(i=0; i<response.to.length; i++) {
var temp = response.request + '_' + response.to[i];
request_ids.push(temp);
}
var requests = request_ids.join(',');
$.post('/FB_Invitaciones', { uid: document.getElementById("FBUser").value, request_ids: requests }, function (resp) {
// callback after storing the requests
});
} else
{
alert('canceled');
}
}
Server Side
<?php
[...]
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $FBAPPID .
"&client_secret=" . $FBSECRETFBAPPID .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = $datos->getFBID();
//Procesando ids
$ids = explode(",",$_REQUEST['request_ids']);
foreach($ids as $request)
{
$apprequest_url ="https://graph.facebook.com/" .$request.
"?".$app_access_token;
$result = file_get_contents($apprequest_url);
}
die()
?>
I can not find the error.
Thanks for the help
I'm found a solution in this question: send app request works, but not sent to user? In my case in the App Configuration I need check "App on Facebook" and now works fine