duanqian6982 2019-05-21 06:43
浏览 55

保存Instagram图像时出现504-Bad Gateway错误

I am trying to save Instagram images on my local machine through API and using the file_put_contents php method

I have tried sleep() method

ini_set('max_execution_time', 400);

$access_token = "";
$photo_count = 8;
$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(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
$cnt = 1;

foreach ($obj['data'] as $post){
    $pic_text = $post['caption']['text'];
    $pic_link = $post['link'];
    $pic_like_count = $post['likes']['count'];
    $pic_comment_count=$post['comments']['count'];
    $pic_src=str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
    $pic_created_time=date("F j, Y", $post['caption']['created_time']);
    $pic_created_time=date("F j, Y", strtotime($pic_created_time . " +1 days"));
    $img = $_SERVER['DOCUMENT_ROOT']."/assets/images/insta-images/".$cnt.".jpg";
    file_put_contents($img, file_get_contents($pic_src));
    $cnt++;
}

With the above code, there are only 4 images are successfully saved on my local machine but I have set photo count 8, the script is running for the only 1 minute.

I want a minimum of 8 images should save

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
    • ¥15 unity连接Sqlserver
    • ¥15 图中这种约束条件lingo该怎么表示出来
    • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
    • ¥15 流式socket文件传输答疑
    • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
    • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
    • ¥15 win10,这种情况怎么办
    • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
    • ¥100 在连接内网VPN时,如何同时保持互联网连接