requests_oauth2 使用教程 [英] Tutorial for using requests_oauth2
问题描述
我正在尝试使用 Python 的 requests-oauth 库向 Pocket 发出请求.不幸的是,使用这个库的描述不是很全面,我也是使用 oauth2 的新手.通常我理解它背后的过程,但仍然无法转换它以使请求工作.
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.
我正在寻找的是更好的文档或一些使用 requests-oauth2 的综合示例.有谁知道.
What I am looking for is abetter documentation or some comprehensive examples to use requests-oauth2. Does anyone know.
特别是当请求仅由本地计算机上的脚本而不是 Web 应用程序发出时,我不明白要使用什么 redirect_url.
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.
推荐答案
我能找到的最佳信息来源是 Github 上 requests-oauth2 项目的文档(当然还有源代码):
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:
该文档还包含一个有趣的阅读材料"部分,其中包含一些指向其他教程的链接.有关 OAuth2 流程的一般概述,请查看本教程:
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:
当然还有老式"python-oauth2 库,它有很好的文档说明:
Of course there is also the "old-fashioned" python-oauth2 library, which is quite well-documented:
该模块的文档包含 Twitter API 的三足身份验证示例.
The documentation of the module contains an example of three-legged authentication for the Twitter API.
关于 redirect_url 字段:通常,您可以在此处使用任何您想要的 URL(甚至是本地地址,例如 http://localhost/my/endpoint
),OAuth 服务器会在对客户端进行身份验证后简单地向客户端发出 HTTP 303 重定向请求,然后在客户端进行处理.但是,某些 API 服务(例如 Twitter)会要求您事先指定 redict_url,并且会拒绝某些 URL(例如基于 IP 的 URL).
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).
这篇关于requests_oauth2 使用教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!