Facebook通话次数限制太高,难以实现(开发中)

时间:2018-09-11 15:15:57

标签: php facebook-graph-api facebook-php-sdk

我刚开始使用Facebook SDK。我正在开发中使用facebook php sdk的项目。我发现计数呼叫的Facebook速率限制太容易达到了。

每次登录,将消耗总呼叫计数速率限制的1%。 登录后,php将运行以下代码:

$accessToken=$_SESSION['fb_access_token'];
$arr=$fb->get('/me/accounts',$accessToken);
$graphedge=$arr->getGraphEdge();
foreach ($graphedge as $graphnode) {

    array_push($this->re_array,$graphnode->asArray());
}
 return true;
  1. 登录+获取用户页面真的消耗了这么多资源吗?
  2. 我的应用上线后,我的速率限制会增加吗?

登录6次后:

enter image description here

我担心我的应用在多次登录后将无法使用,我的登录代码如下:

$helper = $fb->getRedirectLoginHelper();
try {
 $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
 echo 'Graph returned an error: ' . $e->getMessage();
 exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
 if ($helper->getError()) {
  header('HTTP/1.0 401 Unauthorized');
  echo "Error: " . $helper->getError() . "\n";
  echo "Error Code: " . $helper->getErrorCode() . "\n";
  echo "Error Reason: " . $helper->getErrorReason() . "\n";
  echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
  header('HTTP/1.0 400 Bad Request');
  echo 'Bad request';
}
clearlogin();
exit;
}
$oAuth2Client = $fb->getOAuth2Client();

$tokenMetadata = $oAuth2Client->debugToken($accessToken);

$user_id=$tokenMetadata->getUserId();

if (! $accessToken->isLongLived()) {
 try {
   $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
  } catch (Facebook\Exceptions\FacebookSDKException $e) {
     header('Location:index.php');
   exit;
  }
}

0 个答案:

没有答案