2012-09-26 53 views
0

我曾尝试使用Facebook API向朋友发布收视率。但它需要很长时间才能响应,并使我的网页挂起。这是我的代码。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); 

回答

1

我一直在使用Facebook的API张贴在各界朋友的收视尝试。

是不是所有的用户的朋友其实有此张贴到他们的墙上?

这种行为很容易导致他们中的一些标记你的帖子为垃圾邮件...(只是一个警告,它给你的应用程序做什么。)

但它花费很长的时间来响应

这是因为您正在进行一个API调用,因此您的循环中的每个朋友也有一个HTTP请求。

尝试将API调用绑定到一个(或多个)batch requests以加快速度 - 这限制了发生的实际HTTP请求数量,因此应该明显更快。

+0

的帮助将Facebook的考虑我的职位为垃圾邮件。 –

+0

有没有什么办法可以在后端运行这个异步。 –

+0

我了解了Facebook批处理API。谢谢 –

相关问题