Instagram feed based on tag and geolocation

11,179

Solution 1

There is no API to get feed with both tag and location, there are independent APIs for tag and location, but you cannot currently make a single call and get results filtered for both.

Tag API:

https://api.instagram.com/v1/tags/snow/media/recent?access_token=ACCESS-TOKEN

Location search API:

https://api.instagram.com/v1/media/search?lat=48.858844&lng=2.294351&access_token=ACCESS-TOKEN

You can make location API call cache and then manually look for tags, but this may be expensive on number of API calls.. here is an implementation of location search and then you can filter by keyword: http://www.gramfeed.com/instagram/map

Solution 2

As krisrak said - you need to choose: either get by location and then filter by tag or get by tag and then filter by location. check instafeed.js - you can use this for example (get by location and then filter by tag):

var mylocation = 1234569; //must be a number! 

var feed = new Instafeed({
  get: 'location',
  locationId: mylocation,

  clientId: 'someId', //change this with the client id you get from Instagram

  filter: function(image) {
    return (image.tags.indexOf('myTag') >= 0);
  }
});
feed.run();

You can find the location you want in google maps. right click the specific point on the map and choose "what's here?" - this will reveal the coordinates. now use this site to get the Instagram locationId.

Notice that image object has all the properties returned by the Instagram api, so you can get the tags, the location, comments... fora full list of fields look at returned media api (click on response button).

but just remember: filter function must return boolean!

Share:
11,179
Mark Redfern
Author by

Mark Redfern

Firstly I am a husband and a dad, who loves to race pocket bikes, cycle steep hills and to keep myself and my family in the life to which we have become accustomed, I try my best at writing code.

Updated on August 01, 2022

Comments

  • Mark Redfern
    Mark Redfern almost 2 years

    Is it possible to get an instagram feed based on both a tag and location?

    I want all the images tagged with #stackExchange located in Johannesburg ( and surrounding radius of 100 km )

  • Steve Weaver Crawford
    Steve Weaver Crawford over 10 years
    Note that the location search has a maximum radius of 5km
  • Mark Redfern
    Mark Redfern over 10 years
    We are currently getting all the feed items by location search and then programmatically filtering by tag, but that has potential to become troublesome. I was just wondering if there was an api like twitter has where you can combine both searches to save processing. @SteveCrawford where did you see the limitation on the radius?
  • Steve Weaver Crawford
    Steve Weaver Crawford over 10 years
    instagram.com/developer/endpoints/locations Under GET /locations/search : "DISTANCE - Default is 1000m (distance=1000), max distance is 5000."
  • Micro
    Micro almost 10 years
    when you search by location like this, how specific is it? I mean, if you put in the cords for new york city, how will it know how big a radius to take?
  • Mark Redfern
    Mark Redfern almost 10 years
    It seems the only way is to filter locally, such a pity
  • Hamza
    Hamza over 9 years
    hey I am wondering ,how to get the location id , and from where ?, i could not get this in Instagram API documentation so far ?