python - 通过 Twitch 用于桌面应用程序的 OAuth 2.0 授权令牌
问题描述
在用户同意访问后,我一直在寻找一种将 OAuth 令牌传递给我的 python 脚本的方法。首先想到的是建立一个临时的本地服务器来获取令牌并完成。我找到了一个支持它的库。据我所知,我应该设置回调 URL 并重定向到http://localhost
本地网络服务器以接收令牌。但是有一个问题,图书馆要我编辑我的主机文件,并在那里放置该uri的虚假记录,它再次指向我的本地主机,目前无法正常工作。这是代码:
scopes = ['user:read:email', 'user:read:subscriptions']
service_information = ServiceInformation('https://id.twitch.tv/oauth2/authorize',
'https://id.twitch.tv/oauth2/token',
'client_id',
'client_secret',
scopes)
manager = CredentialManager(service_information)
redirect_uri = 'http://localhost:3128'
# Never reaches here
url = manager.init_authorize_code_process(redirect_uri)
_logger.info('Open this url in your browser\n%s', url)
code = manager.wait_and_terminate_authorize_code_process()
_logger.debug('Code got = %s', code)
manager.init_with_authorize_code(redirect_uri, code)
_logger.debug('Access got = %s', manager._access_token)
让我知道是否有更好的方法可以做到这一点,或者我的设置方式是否有问题。
解决方案
推荐阅读
- sql - PostgreSQL 为什么通过函数传递参数比临时表快 3 倍
- batch-file - 批处理 - For 循环中的可变子字符串,具有可变范围
- reactjs - 从子组件函数接收参数
- c++ - 当我更改其他 Mat 对象时,Mat 值会更改
- c# - 如何验证 Apigee Edge 从 .NET/C# 代码生成的 JWT 令牌?
- swift - 通过函数传递时不能修改对象数组?
- c++ - 如何编码为 STL IO 操纵器函数的样式?
- android - 从 api json 检索/显示多个超链接(反应本机)
- r - 如何替换收集匹配词?
- django - 如何使用 celery worker 从 SQS 轮询消息,消息为 JSON 格式,并且 worker 无法解码该格式