Instagram API仅在foreach循环中显示第一项

时间:2018-08-30 11:24:19

标签: php instagram-api

正在为此寻求帮助。我已经使用api创建了一个instagram画廊。当我print_r json输出时,我得到了包含所有12条帖子的完整数组,但是当我回显出foreach循环中的内容时,我仅获得了显示列表中的第一条帖子。谢谢你的帮助。跳只是我错过的愚蠢的事情。

这是我的代码:

<?php
    $access_token = "xxxxxxxxxxxxxxxx";
    $photo_count  = 12;

    $json_link = "https://api.instagram.com/v1/users/self/media/recent/?";
    $json_link .= "access_token={$access_token}&count={$photo_count}";

    $json = file_get_contents($json_link);
    $obj  = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
    //print_r($json);
?>
<div id="instafeed">
    <?php
        foreach($obj['data'] as $post){

            $pic_text     = $post['caption']['text'];
            $pic_link     = $post['link'];
            $pic_src      = str_replace("http://", "https://", $post['images']['low_resolution']['url']);
            $pic_time     = date('d-m-Y H:i', $post['caption']['created_time']);
            $pic_icon_src = $post['user']['profile_picture'];
            $pic_handle   = $post['user']['username'];
            ?>
            <div class="social-block">
                <a href="<?php echo $pic_link; ?>" target="_blank" title="<?php echo $pic_text; ?>">
                    <img src="<?php echo $pic_src; ?>" title="<?php echo $pic_text; ?>" width="100% " height="auto">
                    <div class="insta-acc">
                        <span class="insta-icon"><img src="<?php echo $pic_icon_src; ?>" title="Uk Pro Surf on Instagram"></span>
                        <div>
                            <span class="insta-handle">@<?php echo $pic_handle; ?></span>
                        </div>
                    </div>
                    <span class="insta-text"><p><?php echo $pic_text; ?></p></span>
                </a>
            </div>
            <?php
        }
    ?>
</div>

0 个答案:

没有答案