簡體   English   中英

Facebook 朋友數?

[英]Facebook Friends Count?

統計 Facebook 用戶的朋友的最佳方法是什么...

我目前正在使用(PHP):

$data = $facebook->api('/me/friends');
$friends_count = count($data['data']);

而且它非常慢......(大約2秒)

查詢 facebook api 向 facebook 發送請求。 因為它是一個常見的 http 請求,所以這可能需要大部分時間。 通常沒有辦法解決它。 如果您更頻繁地需要這些值,則應將它們緩存在某處

if (file_exists($cacheFile)) {
  $data = file_get_contents($cachefile);
} else {
  $data = $facebook->api('/me/friends');
  file_put_contents($cacheFile, $data);
}
$friends_count = count($data['data']);

記得不時更新緩存文件。

If you are not processing the data given by Facebook on server side, instead of doing it using PHP, you can use JavaScript graph API to fetch, it can fetch it using ajax which wont effect your page load time.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM