I am trying to use the requests-oauth library for Python to make a request to Pocket. Unfortunately the description to use this library is not very comprehensive and I am also new to use oauth2. Generally I understand the process behind it but still can not convert this to get the request to work.
What I am looking for is abetter documentation or some comprehensive examples to use requests-oauth2. Does anyone know.
Especially I am not understanding what redirect_url to use when the request is made only by a script on my local machine but not a web application.
The best source of information that I could find is the documentation (and of course the source code) of the requests-oauth2 project on Github:
The document also contains an "Interesting readings" section with some links to additional tutorials. For a general overview of the OAuth2 process flow, have a look at this tutorial:
Of course there is also the "old-fashioned" python-oauth2 library, which is quite well-documented:
The documentation of the module contains an example of three-legged authentication for the Twitter API.
Concerning the redirect_url field: In general, you can use any URL you want here (even local addresses such as http://localhost/my/endpoint
), the OAuth server will simply issue a HTTP 303 redirect request to the client after authenticating him, which is then processed on the client-side. However, some API services (such as Twitter) will require you to specify the redict_url beforehand and will refuse some URLs (e.g. IP-based ones).
If you're a fan of the requests Python library, I recommend using requests-oauthlib. It has great documentation and active developers.
Normally you setup the redirect_url
in your application's settings on the API providers website. It looks like Pocket only supports browser based authentication, so you'll need a web browser to generate an access token that you can then embed in your script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With