Search code examples
oauthpython-requestsinstagrampython-3.4instagram-api

Getting instagram photos by location/timestamp


So I built a basic Python function for this purpose, but it's only returning empty lists? I've seen other online answers to this problem which involve getting out of the sandbox for the API, but I'm not sure how to do that? This isn't an application or anything, it's a small test script.

The script is as follows:

def get_instagram_posts(name, time, coordinates):
    max_time_dt = time + timedelta(hours=3)
    min_time_dt = time - timedelta(hours=1)

    milli_max_time = int(calendar.timegm(max_time_dt.timetuple()))
    milli_min_time = int(calendar.timegm(min_time_dt.timetuple()))

    max_time = str(int(milli_max_time/1000))
    min_time = str(int(milli_min_time/1000))

    # Time has to be in seconds (no milliseconds).
    # See http://stackoverflow.com/questions/21091543/ajax-call-to-instagram-get-media-search-timestamp-issue

    dist_rad_str = str(insta_dist_radius_m)
    count_str = str(insta_count)

    api = InstagramAPI(access_token=insta_access_token, 
        client_secret=insta_client_secret)

    # https://www.instagram.com/developer/endpoints/media/

    r = api.media_search(name, count_str, str(coordinates[0]),
        str(coordinates[1]), min_time, max_time)

    print(r)

Is there any way to do this? (Changing permissions, changing the query, changing the source API, I'm up for any solution really).

Thank you so so so much, I've been working on this query for like four hours with nothing.


Solution

  • you cannot get results in sandbox mode, you have to use API to build a platform or app following instagram usecase and guidlines and then get reviewed by instgram to go live. if not use an existing app that does what you are looking for.