You need an instagram account and a facebook account. For demo purposes I am going to use my instagram and my facebook account.
Go to the facebook developers page and click create app
We are almost there! Keep going!
We now want to sort out access. This is done by first getting an authorisation code from instagram via your browser
Following the instructions here you must build a url like the one below using your instagram app id and your redirect_uri which in this case is my home page.
https://api.instagram.com/oauth/authorize?client_id=285542483218899&redirect_uri=https://www.chriswedgwood.com/&scope=user_profile,user_media&response_type=code
Click allow
You will be returned to your home page but with a code in the url
Get that code although ignore the last two characters "_#" !!!
Okay now we can go to python and use this code to get a token. The code can only be used once.
client_id is the Instagram app ID and client_secret is Instagram App Secret
Okay so this gives us a response with a short lived token which is only valid for one hour.
We can use this to get a long lived token that is valid for 60 days that we can perpetually renew.
Hallelujah!!! We have a long lived token. You must be exhausted by now. I am . What a mission!!
Now we can finally use this long lived token to query the api and actually get some data to use on our site.
Success ..... we have data from my instagram account and we have a token to access it that is valid for 60 days.
Now I bet you are wondering what happens when the token expires? No problem you need to refresh it like so.
The basic idea is that you store the token on the server or in the db with an expiry date and before it expires that you renew it.
In my use case I only have to worry about this token but you can easily see how this approach can be extended to many users who authenticate to your app
with instagram/facebook etc.
I will build a Django app in pt 2 that can be used in any of my projects going forward that will need this functionality.
Thanks :)