我无法让用户将App请求转发给他的朋友;
我正在使用客户端中的下一个代码:
window.fbAsyncInit = function() {
FB.init({
appId: 'FBAPPD',
frictionlessRequests: true,
status : true,
cookie : true,
xfbml : true
});
};
当用户选择她的朋友时:
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');
}
}
服务器端
<?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()
?>
我找不到错误。
感谢您的帮助
答案 0 :(得分:0)
我在这个问题上找到了解决方案: send app request works, but not sent to user? 在我的应用程序配置中,我需要检查“Facebook上的应用程序”,现在工作正常
答案 1 :(得分:-1)
@gokuhs复制过去并试试这个1工作正常...将设计更改为您的要求也将您的App id和secrot代码 但是从后退部分我有问题......如果有人给出解决方案我准备支付,我可以给我的ftp和facebook登录细节
<?php
session_start();
if(!empty($_REQUEST['request_ids'])) {
require_once('src/facebook.php');
$config = array();
$config["appId"] = "XXXXXXX";
$config["secret"] = "XXXXXXX";
$config["fileUpload"] = false; // optional
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $config["appId"],
'secret' => $config["secret"],
'cookie' => true,
));
echo $user_id= $facebook->getUser();
// Here I want to retreive Type, color and message.
}
else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="js/jquery-1.6.2.min.js" type="text/javascript" ></script>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<title>Greetings</title>
</head>
<body>
<div align="center"> </div>
<div class="main">
<div style="margin-left:300px; width:540px; margin:auto;">
<table>
<tr>
<td height="39">
<span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Type :</span>
</td>
<td>
<select id="catag">
<option>Love</option>
<option>Friend</option>
<option>Mother</option>
<option>Father</option>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td height="56">
<span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Color :</span>
</td>
<td>
<select id="datas">
<option>Red</option>
<option>Yellow</option>
<option>Blue</option>
<option>Red</option>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td>
<span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Greeting :</span>
</td>
<td>
<textarea type="text" name="message" id="msg" style="height:40px; width:350px;" ></textarea>
</td>
<td>
<input type="submit" value="Send" id="one" style="color:#CCC; background-color:#603; border:none; width:80px; height:40px;"
onclick="sendRequestViaMultiFriendSelector(); return false;"></span>
</td>
</tr>
</table>
</div>
<script>
FB.init({
appId : 'XXXXXX',
status : true,
cookie : true,
frictionlessRequests: true,
oauth: true
});
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: $("#msg").val(),
data: $("#datas").val(),
},function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
//var requestID = FB.api("/requestID", callback);
alert("Post was published.");
}
</script>
<div id="fb">
</div>
<?php }?>
</div>
</body>
</html>