【问题标题】:Instagram Basic display API how to get latest images in PHP?Instagram 基本显示 API 如何在 PHP 中获取最新图像?
【发布时间】:2020-04-17 13:24:31
【问题描述】:

Instagram 如何现在获取最新的 Instagram 图片它正在获取最旧的图片

我正在使用该代码 -

function insta( $api_url ){
    $connection_c = curl_init(); // initializing
    curl_setopt( $connection_c, CURLOPT_URL, $api_url ); // API URL to connect
    curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
    curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
    $json_return = curl_exec( $connection_c ); // connect and get json data
    curl_close( $connection_c ); // close connection
    return json_decode( $json_return ); // decode and return
}
$return = insta("https://graph.instagram.com/me/media?fields=id,caption&access_token=xyz");

为什么只有 25 张图片来了?

这是我遵循的文档 - 1 - https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

2 - https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media

【问题讨论】:

  • 您有 API 文档的链接吗?是否指定返回的默认图像数量?
  • @NigelRen 我在我的问题中提到了 doc,但我没有看到任何默认数字
  • 在响应 JSON 中,您有 "paging 值吗?也许你需要继续调用它来获取额外的图像。
  • @NigelRen 是的,我认为分页值会在那里,但我只需要最新的 5 张图片,只需要最新的日期

标签: php instagram instagram-api instagram-graph-api


【解决方案1】:

`

$connection_c = curl_init(); // initializing
curl_setopt( $connection_c, CURLOPT_URL, "https://graph.instagram.com/me/media?fields=id&access_token=TOKEN" );
curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); 
curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
$json_return = curl_exec( $connection_c );
curl_close( $connection_c );
$dataArray= json_decode( $json_return, true ); 

        foreach($dataArray["data"] as $key=>$val)
        {

            $connection_c = curl_init(); // initializing
            curl_setopt( $connection_c, CURLOPT_URL, "https://graph.instagram.com/".$val["id"]."?fields=id,media_type,media_url,username,timestamp&access_token=TOKEN" ); // API URL to connect
            curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
            curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
            $json_return = curl_exec( $connection_c ); // connect and get json data
            curl_close( $connection_c ); // close connection
            $mediaArray= json_decode( $json_return, true ); // decode and return
            var_dump($mediaArray);
        }

?>`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多