Instagram用户位置API

6
如何在Instagram API中找到用户位置? Instagram端点具有此URI:https://api.instagram.com/v1/locations/{location-id}?access_token=ACCESS-TOKEN
请注意,您需要使用访问令牌才能使用此API终端。
2个回答

6
您可以通过利用媒体源上的位置服务来大致确定用户的位置。也就是说,您可以从一个或多个所需用户发布的图像中提取位置标记。然后,您可以使用所有用户的图像来得出一个大致的位置或类似的东西。
请注意,并非每张图像都有位置标记,有些用户完全关闭了位置服务,在这种情况下,没有任何图像会被标记。但您可以按照以下步骤操作:
使用@instagram的一张具有位置信息的图片的图像ID。然后使用Python库连接到Instagram API以获取该图像的信息。接着访问该图像的位置信息即可。
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)

给出结果为(51.565501504,-0.089821461)


这太棒了,伙计。 - Walrus the Cat

2

补充jstnstwrt的回答,最直接的方法是:

如果你安装了Python的python-instagram库,可以进行以下操作:

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

编辑于2019年7月25日:

这个方法已经不再有效,因为Instagram已经严格限制了他们的API。我建议使用类似instaloader(https://pypi.org/project/instaloader/)这样的工具。


jstnstwrt提到从媒体ID而不是用户ID获取位置信息。我认为API不会返回用户的位置。 - motatoes
@Wboy 谢谢,我已经安装了这个模块,但是我无法获取位置信息,能帮忙吗? - taga

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接