2

I want to get all images within a location from the Instagram API.

Here is my code in python:

from instagram.client import InstagramAPI

client_id = ********
client_secret = ******* 
access_token = *******
client_ip = *******

q = None
count = 100
lat = 51.51608899635712
lng = 0.09891956707558282
min_timestamp, max_timestamp = None, None
distance = 1000

api = InstagramAPI(client_id=client_id, client_secret=client_secret, client_ips=client_ip, access_token=access_token)

media_all_ids = []
media_ids, next = api.media_search(q, count, lat, lng, min_timestamp, max_timestamp, distance)

for media_id in media_ids:
    media_all_ids.append(media_id.id)

The main problem is it gives me this error:

media_ids,next = api.media_search(q, count, lat, lng, min_timestamp, max_timestamp, distance)
ValueError: too many values to unpack

I want to print out their IDs alongside their image link and the time the photo was captured.
I was wondering if someone knows how to solve this issue?

Forge
  • 6,538
  • 6
  • 44
  • 64
Mr_Shoryuken
  • 719
  • 3
  • 8
  • 16

2 Answers2

1
https://www.instagram.com/explore/locations/US/united-states/?__a=1&page=1

This page returns all the locations in the instagram in the first page, loop through 1 to 12 to get all the US cities ( This is without use of API )

0

The correct use of the media_search method is:

media_list = api.media_search(q, count, lat, lng, min_timestamp, max_timestamp, distance)

The method returns a list of Media objects.
It does not return a list of media object IDs, you might got confused because printing a Media object will print only its ID, see the code here.

Check out Sample App for more examples on how to use this client.

Forge
  • 6,538
  • 6
  • 44
  • 64