Authorization

Authorization

To access a user's account, the user must first authorize your application so that you can get an access token. Requesting an access token is fairly straightforward: the authorized method will generate the URL for you, you just have to point a browser to the URL. If you configured a callback URL during the API setup, you have an endpoint to save the user data, otherwise you have to copy/paste/parse the generated URL by hand.

import webbrowser
from imgur_python import Imgur

imgur_client = Imgur({'client_id': 'cf8c57ca8......'})
auth_url = imgur_client.authorize()
webbrowser.open(auth_url)

Response example with no callback:

https://imgur.com/#access_token=a955ec9a0b41...........&expires_in=315360000&token_type=bearer&refresh_token=27bd6d219506c46cdcf8.............&account_username=SomeImgurUserName&account_id=1468...

Refresh Tokens

If a user has authorized their account but you no longer have a valid access_token for them, then a new one can be generated by using the refresh_token.

When your application receives a refresh token, it is important to store that refresh token for future use. If your application loses the refresh token, you will have to prompt the user for their login information again.

from imgur_python import Imgur

imgur_client = Imgur({'client_id': 'cf8c57ca8......'})
access_token = imgur_client.access_token()
print(access_token)