Instagram user location with api

16,182

Solution 1

You can approximate the location of a user by exploiting the location services on the media feed. That is, you can pull the location tag from one or more of the desired user's posted images. You could then use all the user's images to come up with an approximate location or something like that.

Note that not every image has a location tag, and some user's have location services turned completely off, in which case no images will be tagged. But you can do it like this:

using the image id for one of @instagram's images that has a location. then connecting to the instagram api using the python library to get info on that image. then accessing the images location.

image_id = '976907440786573124_25025320'
image_info = api.media(image_id)
lat = image_info.location.point.latitude
lon = image_info.location.point.longitude
print (lat,lon)

gives the result (51.565501504,-0.089821461)

Solution 2

To add on to jstnstwrt's answer, the most direct way is:

If you install the python-instagram libary for python, you can do the following:

import instagram
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
id = <id of the user you're trying to get location from>
location = api.location(id) # returns error if no location set
coordinates = location.point #returns point object with lat and long coordinates

EDIT 25/07/2019:

This has long stopped working, instagram has locked down their APIs significantly. I would recommend something like instaloader (https://pypi.org/project/instaloader/) that works decently.

Share:
16,182
Hamidreza shaabani
Author by

Hamidreza shaabani

Updated on July 11, 2022

Comments

  • Hamidreza shaabani
    Hamidreza shaabani almost 2 years

    How can i find user location on intagram api ? instagram endpoints have this uri : https://api.instagram.com/v1/locations/{location-id}?access_token=ACCESS-TOKEN

    enter image description here