【问题标题】:Limit Instagram php feed限制 Instagram php 提要
【发布时间】:2013-06-15 13:53:05
【问题描述】:

我正在寻找有关使用 php instagram 提要的帮助。

我通过研究找到了this link,它运行良好,但我不知道如何限制 instagram 默认为 20 的结果。

我真的只想一次显示 6 张图片。

我对php不是很好,所以请原谅我的无知。

请看下面的代码

<?php
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;
}
$result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE");
$result = json_decode($result);
foreach ($result->data as $post) {
    // Do something with this data.
}
?>

【问题讨论】:

  • 另请注意,最近(2015 年 11 月)为沙盒模式下的应用程序引入了 20 个图像的限制。我花了很长时间才发现这一点,因为谷歌显示的最佳答案没有提到这一点。所以我现在添加。

标签: php api feed instagram


【解决方案1】:

您可以使用 COUNT 参数指定要返回的图像数量。试试这个:

$result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE&count=6");

如果您希望检索更多的记录并在您身边对它们进行分页,请查看 min_id 和 max_id 以进行分页。

【讨论】:

    【解决方案2】:

    限制你的循环

    $items=6;
    
    $i=0;
    
    foreach ($result->data as $post) {
    
       if($i<$items){
    
          // Do something with this data.
    
       }
       else{
    
           break;
    
       }
    
       ++$i;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多