One of the hotter social networks in higher education is Instagram. As a developer you might find yourself needing to pull photos into a website using Instagram's API like we did when we recently added Instagram photos to our central social networking website, Connect with WVU. As with many APIs Instagram requires authentication to access many of its end-points. This is fine but unfortunately the service makes the assumption that you are going to access the end-points on behalf of a particular user that has had the opportunity to give an application permission to access their information. This isn't always the case. Especially when you simply want to access the service to pull your own user's information via a small script.
In our situation we have a social network data collection service that queries the Instagram API every 10 minutes to get the latest photos that have been posted to our WestVirginiaU account. The info is saved to a SQLite database. When users hit connect.wvu.edu a request is made to this service to retrieve the latest information (along with Facebook, Twitter, Google+, YouTube and foursquare data) from the SQLite database.
The trick is that the service simply needs to make requests as the primary account but has no way to login to authenticate and get an an access token for Instagram. A service like Twitter gets this particular use case correct in that they allow you to generate an access token via their developer admin. Instagram doesn't have this feature yet. Hopefully they add it. For now you can do the following.
Generating an Access Token for Instagram
Generating a token to be used in your application is actually fairly straightforward once you know the magical incantation. Just do the following:
- Write down the client ID, client secret, and redirect URI for the client you want to generate an access token for. You can find it on the "Manage Clients" panel in the Instagram Developer's site.
- Visit the following address replacing the client ID and the redirect URI:
- When prompted choose "Yes" to authorize the app
- You'll be redirected to the redirect URI you supplied. At the end of the address you'll see a request variable called
code. Copy the value.
- Open Terminal (or favorite command line tool). Copy and paste the following. Replace the appropriate values:
- Copy the access token from the returned JSON object.
It should also be noted that the generated access token can still expire. It shouldn't expire in the near-term but it's not permanent.