Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram API to fetch pictures with specific hashtags [closed]

Tags:

I want to get all the pictures with a specific hash tag from Instagram using PHP. How can I do that?

like image 298
Shaonline Avatar asked Nov 01 '12 12:11

Shaonline


People also ask

How do you get all hashtags on Instagram with API?

The Hashtag Search API consists of the following nodes and edges: GET /ig_hashtag_search — to get a specific hashtag's node ID. GET /{ig-hashtag-id} — to get data about a hashtag. GET /{ig-hashtag-id}/top_media — to get the most popular photos and videos that have a specific hashtag.

How do I see all posts under a hashtag?

Hashtag pages have an Instagram Story icon in the top left corner. Click on it and you'll see a collection of Stories posts tagged with the hashtag from people with public profiles.

What information can I get from Instagram API?

The API can be used to get and publish their media, manage and reply to comments on their media, identify media where they have been @mentioned by other Instagram users, find hashtagged media, and get basic metadata and metrics about other Instagram Businesses and Creators.


1 Answers

Firstly, the Instagram API endpoint "tags" required OAuth authentication.

You can query results for a particular hashtag (snowy in this case) using the following url

It is rate limited to 5000 (X-Ratelimit-Limit:5000) per hour

https://api.instagram.com/v1/tags/snowy/media/recent

Sample response

{   "pagination":  {     "next_max_tag_id": "1370433362010",     "deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",     "next_max_id": "1370433362010",     "next_min_id": "1370443976800",     "min_tag_id": "1370443976800",     "next_url": "https://api.instagram.com/v1/tags/snowy/media/recent?access_token=40480112.1fb234f.4866541998fd4656a2e2e2beaa5c4bb1&max_tag_id=1370433362010"   },   "meta":  {     "code": 200   },   "data":  [      {       "attribution": null,       "tags":  [         "snowy"       ],       "type": "image",       "location": null,       "comments":  {         "count": 0,         "data":  []       },       "filter": null,       "created_time": "1370418343",       "link": "http://instagram.com/p/aK1yrGRi3l/",       "likes":  {         "count": 1,         "data":  [            {             "username": "iri92lol",             "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",             "id": "404174490",             "full_name": "Iri"           }         ]       },       "images":  {         "low_resolution":  {           "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_6.jpg",           "width": 306,           "height": 306         },         "thumbnail":  {           "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_5.jpg",           "width": 150,           "height": 150         },         "standard_resolution":  {           "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_7.jpg",           "width": 612,           "height": 612         }       },       "users_in_photo":  [],       "caption":  {         "created_time": "1370418353",         "text": "#snowy",         "from":  {           "username": "iri92lol",           "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",           "id": "404174490",           "full_name": "Iri"         },         "id": "471425773832908504"       },       "user_has_liked": false,       "id": "471425689728724453_404174490",       "user":  {         "username": "iri92lol",         "website": "",         "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",         "full_name": "Iri",         "bio": "",         "id": "404174490"       }     } } 

You can play around here :

https://apigee.com/console/instagram?req=%7B%22resource%22%3A%22get_tags_media_recent%22%2C%22params%22%3A%7B%22query%22%3A%7B%7D%2C%22template%22%3A%7B%22tag-name%22%3A%22snowy%22%7D%2C%22headers%22%3A%7B%7D%2C%22body%22%3A%7B%22attachmentFormat%22%3A%22mime%22%2C%22attachmentContentDisposition%22%3A%22form-data%22%7D%7D%2C%22verb%22%3A%22get%22%7D

You need to use "Authentication" as OAuth 2 and will be prompted to signin via Instagram. Post that you might have to reneter the "tag-name" in "Template" section.

All the pagination related data is available in the "pagination" parameter in the response and use it's "next_url" to query for the next set of result.

like image 170
Jaspal Singh Avatar answered Sep 19 '22 16:09

Jaspal Singh