简体   繁体   中英

Limit Instagram Feed in Php-Fetch

i am using the code below, to show some photos of my instagram-account on my website. it just fetches all the images of my account in the div. Is there a way to limit the fetched data to 10 Images or so ?

Cant figure out how to do that..

thanks for your help!

    <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>

您可以使用count参数。

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

It was a problem in Instagram Developer Console. max_id and min_id doesn't work there.

For anyone interested - i found a solution for this problem:

it doesnt work with: {$accessToken}&count=10

But it works with: ?access_token=123456789101112131415123123111&count=10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM