Imgur / imgurpython

Official Imgur python client library (deprecated)
MIT License
546 stars 116 forks source link

Automatic authorization #51

Closed patillacode closed 9 years ago

patillacode commented 9 years ago

Hi,

I was wondering how do an automatic authorization from within the code.

In the README I can see:

# ... redirect user to `authorization_url`, obtain pin (or code or token) ...

But I want to grab the pin automatically, since the authorization url redirects me to the actual url with the pin I am not sure how to follow that stream since the requests library only follows on POST/GET/DELETE methods.

My app has no user interface, I need to get the pin from the code, with no human interaction. Any suggestions?

Thanks!

jacobgreenleaf commented 9 years ago

Can you describe your use case a bit more? We require the end-user to authorize your application at least once so you will need to direct them to the authorize page for their consent. After that it should be possible to programmatically obtain access tokens.

patillacode commented 9 years ago

I want to access my imgur account to push images etc

In order to do this I need authorization, so I need to access the authorization url and from there (getting redirected) I get the pin.

How to do that automatically? I don't want to grab the pin manually every hour to set it up in the code to be able to do this.

btipling commented 9 years ago

You can do that automatically by sending a refresh_token request. This library provides you with a refresh method to achieve this.

I am not sure if it is a problem with this library, but I am looking at providing hooks that fire before any API request to our JavaScript library so that it can enable consumers of the library to automatically attempt a refresh when they see the access_token has expired.

patillacode commented 9 years ago

Well, it seems like I didn't understand the process.

I will look into it again and let you know.

Thanks guys

patillacode commented 9 years ago

Cheers guys, solved. Understood the refresh way of doing it :smile:

Thanks for your help.

jacobgreenleaf commented 9 years ago

Cool, I will close this as fixed / no issue.

ouzkagan commented 3 years ago

Well, it seems like I didn't understand the process.

I will look into it again and let you know.

Thanks guys

lol how??

ouzkagan commented 3 years ago

Oh okay. i understand too -> in the official example https://github.com/Imgur/imgurpython/blob/master/examples/auth.py you get access by pin code. just add your access_token and refresh_token to auth.ini file. then construct a instance of ImgurClient with sendind them as a parameter.

access_token = config.get('credentials', 'access_token')
refresh_token = config.get('credentials', 'refresh_token')

client = ImgurClient(client_id, client_secret, access_token, refresh_token)
client.set_user_auth(access_token, refresh_token)

may be u don't need to send in both of them..

Also delete pin related parts