0

我曾尝试使用 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);
4

2 回答 2

1

我曾尝试使用 facebook api 发布所有朋友的评分。

用户的所有朋友是否都希望将其发布到他们的墙上?

这种行为很容易导致他们中的一些人将您的帖子标记为垃圾邮件……(只是一个警告,这取决于您的应用程序的功能。)

但是需要很长时间才能响应

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

尝试将 API 调用捆绑到一个(或多个)批处理请求中以加快处理速度——这会限制实际发生的 HTTP 请求的数量,因此应该会明显更快。

于 2012-09-26T14:46:58.207 回答