Instagram API

Apps created on or after Nov 17, 2015 will start in Sandbox Mode and function on newly updated API rate-limits and behaviors. Prior to going Live, and being able to be used by people other than the developers of the app, these apps will have to go through a new review process.

Go to https://www.instagram.com/developer/ and login to your Instagram account. If you don’t already have one you have to sign up for Instagram via a mobile app and not the desktop browser.

Once you have logged in, click on Manage Clients (top right hand corner)
Then Register a new Client.

Once you have done this you will be given a Client ID and Client Secret.

Before you can go any further, in order to connect to the Instagram API you need to generate an access token using your secret developer key. There are a couple of ways to do this but I found the most simplest way on this website: http://jelled.com/instagram/access-token

I go to this URL (replacing MY-CLIENT-ID with my actual client ID):
https://instagram.com/oauth/authorize/?client_id=MY-CLIENT-ID&scope=public_content&redirect_uri=http://localhost&response_type=token

It then returns the access token:
http://localhost/#access_token=THIS-IS-MY-NEW-ACCESS-TOKEN

I found this python script here: http://www.pygopar.com/playing-with-instagrams-api/ and I have updated it to work in the sandbox.

from time import sleep
from instagram.client import InstagramAPI

access_token = “MY-NEWLY-GENERATED-ACCESS-TOKEN”
api = InstagramAPI(access_token=access_token,
client_ips=”MY-IP-ADDRESS”,
client_secret=”MY-CLIENT-SECRET”)
recent_media, url = api.tag_recent_media(tag_name=”coding”, count=5) # 1

for media in recent_media:
# Where the media is
id_ = media.id
# List of users that like the image
users = [user.username for user in media.likes]
# If you have already like the picture, do nothing
if “MY-INSTAGRAM-USERNAME” in users:
print(“IN PHOTO”)

# If you haven’t liked the photo then do it
else:
print(“LIKING PICTURE”)
api.like_media(media_id=id_)

# Sleep to make instagram stop complaining
sleep(2)

print (“Done”)

Be the first to comment

Leave a Reply

Your email address will not be published.


*