Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created April 9, 2012 20:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pamelafox/2346466 to your computer and use it in GitHub Desktop.
Save pamelafox/2346466 to your computer and use it in GitHub Desktop.
Instagram Python API Reference

python-instagram

A Python client for the Instagram REST and Search APIs

Installation

pip install python-instagram

Requires

  • httplib2
  • simplejson

Discussion

Visit our Google Group to discuss the Instagram API.

Obtaining an access token

You can use the provided get_access_token.py script to obtain an access token for yourself. It will prompt you for your app's Client ID, Client Secret, and Redirect URI, and walk you through instructions for getting your own access token for your app.

Usage

Here's how you could list the popular media: from instagram.client import InstagramAPI

access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
popular_media = api.media_popular(count=20)
for media in popular_media:
    print media.images['standard_resolution'].url

For some methods, you can just use your client ID and secret instead of an access token:

from instagram.client import InstagramAPI
api = InstagramAPI(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")

Real-time Subscriptions:

See the Real-time API docs for more on these methods: http://instagr.am/developer/realtime/

api.create_subscription(object='tag', object_id='bacon', aspect='media', callback_url=callback_url)
api.list_subscriptions()
api.delete_subscriptions(id=342342)

Data Retrieval:

See the endpoints docs for more on these methods: http://instagr.am/developer/endpoints/ Methods with a * return two values, the second is a pagination parameter.

Users: http://instagr.am/developer/endpoints/users/

api.user(user_id)
api.user_media_feed()*
api.user_liked_media()*
api.user_recent_media(user_id, count, max_id)*
api.user_search(q, count, lat, lng, min_timestamp, max_timestamp)

Relationships: http://instagr.am/developer/endpoints/relationships/

api.user_incoming_requests()
api.user_follows(user_id)*
api.user_followed_by(user_id)*
api.follow_user(user_id)
api.unfollow_user(user_id)
api.block_user(user_id)
api.unblock_user(user_id)
api.approve_user_request(user_id)
api.ignore_user_request(user_id)

Media: http://instagr.am/developer/endpoints/media/

api.media(media_id)
api.media_popular(count, max_id)
api.media_search(q, count, lat, lng, min_timestamp, max_timestamp)

Comments: http://instagr.am/developer/endpoints/comments/

api.media_comments(media_id)
api.create_media_comment(media_id, text)
api.delete_comment(media_id, comment_id)

Likes: http://instagr.am/developer/endpoints/likes/

api.media_likes(media_id)
api.like_media(media_id)
api.unlike_media(media_id)

Tags: http://instagr.am/developer/endpoints/tags/

api.tag(tag_name) 
api.tag_recent_media(count, max_id, tag_name)*
api.tag_search(q, count)*

Locations: http://instagr.am/developer/endpoints/locations/ api.location(location_id) api.location_recent_media(count, max_id, location_id)* api.location_search(q, count, lat, lng, foursquare_id)

Geographies: http://instagr.am/developer/endpoints/geographies/ api.geography_recent_media(count, max_id, geography_id)*

Sample app

We also provide a one-file sample app using bottle (you'll have to 'pip install bottle' first). To try it out:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment