I have tried using facebook api to post the ratings on the friends all. but it is taking a long time to respond and makes my webpage hang. here is my code.
I am getting the user info through Facebook connect. once i connected , i set the user id in the session and allowing the user to rate the product on my page. once the rating is submitted , i am posting the user rating values eg. 4.5 stars to the user’s Facebook wall and also on the friends page. but the page is taking a long to respond back. Is there any way to work out this. i am expecting some thing like , the posting process should happen in the back end without the user notice and the page should respond to him very fast.
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);
Do all of the user’s friends actually want to have this posted to their wall?
This behavior could easily lead to some of them flagging your posts as spam … (Just a warning, it’s up to you what your app does.)
That’s because you’re making one API call and therefor also one HTTP request for each friend in your loop.
Try bundling the API calls into one (or more) batch requests to speed things up – this limits the amount of actual HTTP requests happening, and therefore should be noticeably quicker.