A Python client for the Instagram REST and Search APIs
pip install python-instagram
- httplib2
- simplejson
Visit our Google Group to discuss the Instagram API.
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.
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")
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)
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)*
We also provide a one-file sample app using bottle (you'll have to 'pip install bottle' first). To try it out:
- Set your redirect URI to 'http://localhost:8515/oauth_callback' in your dev profile
- Open up sample_app.py, update it with your client_id and secret, and set redirect URI to 'http://localhost:8515/oauth_callback'
- Run the file; it will host a local server on port 8515.
- Try visiting http://localhost:8515 in your browser