« image onload | メイン | wordpressでvisualモードでタグが消える »

2024年01月06日

インスタグラム全画像取得


<?PHP


$instaBusinessId = '1111111111111111111111';
$accessToken = 'EAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDJfMZD';
$instaAccountName = 'some_one'; //  

$url = 'https://graph.facebook.com/v17.0/' . $instaBusinessId . '?fields=business_discovery.username(' . $instaAccountName . ')%7Bmedia.limit%28500%29%7Bmedia_url,media_type,children%7Bid,media_url,media_type%7D,thumbnail_url%7D%7D&access_token=' . $accessToken;

$res = file_get_contents($url);

$arr = json_decode($res, true);
$url_list = [];
foreach ($arr["business_discovery"]["media"]["data"] as $t_file) {

    if ($t_file["media_type"] == "VIDEO") {
        continue;
    }elseif($t_file["media_type"] == "IMAGE") {
        $url_list[] = $t_file["media_url"];
    }elseif($t_file["media_type"] == "CAROUSEL_ALBUM") {
        foreach($t_file['children']["data"] as $tt_dat){
            if($tt_dat["media_type"] == "IMAGE") {
                $url_list[] = $tt_dat["media_url"];
            }
        }
    }
}
$i=1;
foreach($url_list as $t_rul){
    $res = file_get_contents($t_rul);
    $fp = fopen($i.".jpg","w");
    fwrite($fp,$res);
    fclose($fp);
    $i++;
}

投稿者 muuming : 2024年01月06日 10:36

コメント

コメントしてください




保存しますか?