SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   function scrape_insta_hash($tag) {
  3.       $insta_source = file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/'); // instagrame tag url
  4.       $shards = explode('window._sharedData = ', $insta_source);
  5.       $insta_json = explode(';</script>', $shards[1]);
  6.       $insta_array = json_decode($insta_json[0], TRUE);
  7.       return $insta_array; // this return a lot things print it and see what else you need
  8.   }
  9.  
  10.   $tag = "sanfranciscolandscape";
  11.   $results_array = scrape_insta_hash($tag);
  12.  
  13.   $limit = 5; // provide the limit thats important because one page only give some images then load more have to be clicked
  14.  
  15.   for ($i=$limit; $i >= 0; $i--) {
  16.     if(array_key_exists($i,$results_array['entry_data']['TagPage'][0]["graphql"]["hashtag"]["edge_hashtag_to_media"]["edges"])) {
  17.       $latest_array = $results_array['entry_data']['TagPage'][0]["graphql"]["hashtag"]["edge_hashtag_to_media"]["edges"][$i]["node"];
  18.  
  19.       $newPosting = [
  20.         "image"=>$latest_array['display_url'],
  21.         "thumbnail"=>$latest_array['thumbnail_src'],
  22.         "instagram_id"=>$latest_array['id'],
  23.         // "caption"=>$latest_array['caption']['edge_media_to_caption']['edges'][0]["node"]["text"],
  24.         "link"=>"https://www.instagram.com/p/".$latest_array['shortcode'],
  25.         "date"=>$latest_array['taken_at_timestamp']
  26.       ];
  27.  
  28.       echo "<pre>";
  29.       print_r($newPosting);
  30.       echo "/<pre>";
  31.     }
  32.   }
  33. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top