6
這是我用來獲取沒有API的hashtag圖像的代碼。我不想使用任何憑據。無需添加client_id
或訪問令牌。但我只能得到15張圖片。我如何獲得所有圖像?如何在沒有API的情況下在Instagram中獲取所有hashtag圖片?
<div>
<form action='#' method='post'>
<input type='input' name='txttag' />
<input type='submit' value='Get Image' />
</form>
</div>
<?php
function scrape_insta_hash($tag) {
$insta_source = file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/'); // instagrame tag url
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array; // this return a lot things print it and see what else you need
}
if(isset($_POST['txttag']))
{
$tag =$_POST['txttag']; // tag for which ou want images
$results_array = scrape_insta_hash($tag);
$limit = 15; // provide the limit thats important because one page only give some images then load more have to be clicked
$image_array= array(); // array to store images.
for ($i=0; $i < $limit; $i++) {
$latest_array = $results_array['entry_data']['TagPage'][0]['tag']['media']['nodes'][$i];
$image_data = '<img src="'.$latest_array['thumbnail_src'].'">'; // thumbnail and same sizes
//$image_data = '<img src="'.$latest_array['display_src'].'">'; actual image and different sizes
array_push($image_array, $image_data);
}
foreach ($image_array as $image) {
echo $image;// this will echo the images wrap it in div or ul li what ever html structure
}
//https://www.instagram.com/explore/tags/your-tag-name/
}
?>
<style>
img {
height: 200px;
margin: 10px;
}
</style>
能否請你告訴我如何與你的代碼打印超過20張。 –
@jigsparmar看到更新 – ilyapt
非常感謝你.. –