我尝试使用facebook api在所有朋友上发布评分。但它需要很长时间才能回复并使我的网页挂起。这是我的代码。
我通过Facebook连接获取用户信息。一旦我连接,我在会话中设置用户ID,并允许用户在我的页面上评价产品。一旦提交评级,我就会发布用户评级值,例如。 4.5星到用户的Facebook墙和朋友页面。但该页面需要很长时间才能回复。有没有办法解决这个问题。我期待一些事情,发布过程应该在后端发生而没有用户通知,页面应该非常快地响应他。
if($user)
{
$accessToken = $facebook->getAccessToken();
$ret_obj= $facebook->api('/me/feed', 'post', array(
'access_token' =>$accessToken,
'message' => $message,
'link' => $link,
'name' => strip_tags($pagetitle),
'picture' => $picture,
'caption' => $caption,
'description' => $description,
));
$mypostid = $ret_obj['id'];
$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend) {
$frendid = "/".$friend['id']."/feed";
$frend_return = $facebook->api($frendid, 'post', array(
'access_token' =>$accessToken,
'message' => $message,
'link' => $link,
'name' => strip_tags($pagetitle),
'picture' => $picture,
'caption' => $caption,
'description' => $description,
));
}
}
$insert = mysql_query("INSERT INTO `rating`
(
`id`,
`user_id`,
`username`,
`useremail`,
`rateformoney`,
`ratefordesign`,
`rateforperform`,
`rateforfeatures`,
`rateforquality`,
`avgrating`,
`ratingcomment`,
`recommended`,
`category`,
`product_id`,
`created_date`
)
VALUES
(
NULL,
'$usrid',
'$name',
'$email',
'$rat_price', '$rat_design', '$rat_perf', '$rat_feat', '$rat_qlt', '$avgrating',
'$rat_comment', '$recommended', '$category', '$productid', CURRENT_TIMESTAMP
)
");
header($redirect);
答案 0 :(得分:1)
我尝试使用facebook api在所有朋友上发布评分。
所有用户的朋友是否想将其发布到他们的墙上?
这种行为很容易导致其中一些人将您的帖子标记为垃圾邮件......(只是警告,这取决于您的应用所做的事情。)
但需要很长时间才能回复
那是因为你正在进行一次API调用,因此你的循环中每个朋友也会有一个HTTP请求。
尝试将API调用捆绑到一个(或多个)batch requests中以加快速度 - 这会限制实际发生的HTTP请求的数量,因此应该明显更快。
答案 1 :(得分:0)