duan0714 2014-07-16 10:22
浏览 48
已采纳

Instagram API - 在第一页上没有返回正确数量的图像

I need the feed to provide seven images at a time. For some reason, all pages provide seven except the first page which only provides 5.

<?php
function fetchData($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    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;
}

$maxtagid = (isset($_GET['instatag'])) ? $_GET['instatag'] : false;
$url = "https://api.instagram.com/v1/users/self/feed?access_token=$accesstoken&count=7";
if($maxtagid){
    $url .= "&max_id=$maxtagid";
}
$result = json_decode(fetchData($url)); 
foreach ($result->data as $post) echo '<div class="insta-square"><a target="_blank" href="'.$post->link.'"><img src="'.$post->images->standard_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" /></a></div>';
$nextmax = $result->pagination->next_max_id;
if($nextmax != ''){ ?>
    <div class="insta-square"><a href="<?php echo get_home_url(); ?>/gallery?instatag=<?php echo $nextmax; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/next-slide-square.png" /></a></div>
<?php } ?>

I have played around with all kinds of settings, if $maxtagid is set, removing the VERIFYPEER, etc. and nothing seems to work. What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • douweibiao8471 2014-07-16 10:32
    关注

    I think the max_id parameter is causing issue on first page.. try this solution:

    <?php
    function fetchData($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        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;
    }
    
    $maxtagid = (isset($_GET['instatag'])) ? $_GET['instatag'] : false;
    $url = "https://api.instagram.com/v1/users/self/feed?access_token=$accesstoken&count=7";
    if($maxtagid){
         $url .= "&max_id=$maxtagid";
    }
    $result = json_decode(fetchData($url));
    foreach ($result->data as $post) echo '<div class="insta-square"><a target="_blank" href="'.$post->link.'"><img src="'.$post->images->standard_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" /></a></div>';
    $nextmax = $result->pagination->next_max_id;
    if($nextmax != ''){ ?>
        <div class="insta-square"><a href="<?php echo get_home_url(); ?>/gallery?instatag=<?php echo $nextmax; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/next-slide-square.png" /></a></div>
    <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案