我刚开始使用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;
登录6次后:
我担心我的应用在多次登录后将无法使用,我的登录代码如下:
$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;
}
}