[英]Facebook graph api php getting pictures too slow
嗨,在我的新Facebook應用程序中,我嘗試為屏幕上的用戶加載一系列個人資料圖片。 問題是,它花費的時間太長。 這是我目前正在獲取圖片的方法-還有什么我可以做以加快速度嗎? 執行大約需要10秒以上的時間。
我使用的是燈箱,僅在單擊屏幕上的第一張圖像后才真正需要加載其他圖片,但不確定如何執行此操作。
//First off we need to get some profile pics for the user:
$getuseralbumsurl = "https://graph.facebook.com/". $row['FB_ID'] ."?fields=albums&access_token="
. $access_token;
$getuseralbums = json_decode(file_get_contents($getuseralbumsurl));
$getuseralbums = $getuseralbums->albums;
foreach( $getuseralbums->data as $album ){//Getting profile pics for user.
if($album->type == "profile"){ //get profile picture album
$albumid = $album->id;
$photosurl = "https://graph.facebook.com/" . $albumid . "/photos?access_token=". $access_token ."&limit=3";
$profilephotos = json_decode(file_get_contents($photosurl));
$counter = 0;
foreach( $profilephotos->data as $image ){
if($counter == 3)//we only want 3 photos from the album.
break;
if($lowerbound == 0)
$photosurlarray['group1'][] = $image->source;
else if($lowerbound == 1)
$photosurlarray['group2'][] = $image->source;
else
$photosurlarray['group3'][] = $image->source;
$counter++;
}
break;//we don't need anymore albums.
}
謝謝!
另一種方法是通過PHP使用緩存方法。 您可以將其設置為每5分鍾通過PHP定期檢查一次圖片,然后將生成的HTML保存到.txt文檔或類似文件中。 然后,您只需將.txt文檔中的代碼檢索到您的實時網站中。 這將保證您的網站的任何訪問者都能立即加載。
我最終通過使用批處理請求解決了該問題,並在頁面完成加載后(使用AJAX)產生了在后台運行的作業。 這似乎已經成功了!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.