2015-02-12 58 views
0

我使用下面的代碼來顯示我的網站上我的instagram帳戶的一些照片。它只是提取我​​的帳戶在div中的所有圖像。有沒有辦法將獲取的數據限制在10張左右?限制Instagram Feed在Php-Fetch

不知道該怎麼做..

感謝您的幫助!

<div id="instagramfeed"> 


<?php 
     // Supply a user id and an access token 
     $userid = "123xy"; 
     $accessToken = "123xy "; 

     // Gets our data 
     function fetchData($url){ 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
      $result = curl_exec($ch); 
      curl_close($ch); 
      return $result; 
     } 

     // Pulls and parses data. 
     $result = fetchData("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}"); 
     $result = json_decode($result); 
    ?> 


    <?php foreach ($result->data as $post): ?> 
     <!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) --> 
     <a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a> 
    <?php endforeach ?> <br><br><br><br> 


</div> 

回答

0

您可以使用count參數。

https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}&count=10 
+0

是的,我想在這之前...對不起,didnt比如說。當我這樣做,該div完全是空的..我不知道爲什麼會發生.. :( – user3599221 2015-02-12 08:28:37

0

這是在Instagram開發者控制檯中的一個問題。 max_id和min_id在那裏不起作用。

0

任何有興趣 - 我發現這個問題的解決方案:

它不與工作:{$accessToken}&count=10

但它的工作原理: ?access_token=123456789101112131415123123111&count=10

相關問題