首页 > 解决方案 > 通过 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)

让我知道是否有更好的方法可以做到这一点,或者我的设置方式是否有问题。

标签: pythonoauth-2.0python-requeststwitch-api

解决方案


推荐阅读