Command line interface with oauth automation for testing Instagram's API during development process
Command line interface with OAuth automation for testing Instagram’s API during development process
This is in no way intended to replace Instagram’s Python library, which is available on Github. The primary value proposition of this script is that, unlike the access token procurement process provided by the Instagram Python library, the OAuth process here is entirely automated using Selenium. The automation is intended to streamline the development process so that you don’t have to bother with the semi-manual process of getting a new OAuth token for every session, but instead can just focus on calling the endpoints and exploring the responses you get back. To that end, the script is a command line interface for Instagram’s API and of course all of the request functions included therein are easily extensible and can be adapted to whatever Python-based application you’re integrating with Instagram.
A few things before you get started:
driver = webdriver.Chrome()
Setting up your user and client credentials for OAuth token-grab process:
Initial setup for this script requires you to provide the following credentials:
Run $ python InstagramAPICORE.py get_creds
and submit all of the above at the appropriate prompts. The get_creds
command will store your credentials in the creds.json
file and trigger Selenium to open an instance of Chrome in order to grab the final OAuth token for your session. The final access token for this session will be stored the finalToken.json
file.
Instagram’s access tokens do not specify an expiration time but typically a token will at least last 24 hours, sometimes longer. When you eventually get an API response that contains error_type=OAuthAccessTokenError
, run the following command: $ python InstagramAPICORE.py refresh_token
to obtain a new access token with your original credentials.
Using the script:
The help option is as follows:
$ python InstagramAPICore.py --help
An example using the tag_info
command:
$ python InstagramAPICore.py tag_info seattle
This returns some basic information on the tag “seattle”:
{"meta":{"code":200},"data":{"media_count":7482177,"name":"seattle"}}