如何自动化oauth流来检索凭证?

2024-04-23 22:34:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个python脚本,它调用google分析api来获取一些实时数据,然后将其存储在数据库中。但是在调用api之前,我必须获得oauth令牌。你知道吗

这就是我到目前为止所做的,只需要一点手工劳动,点击链接,获取验证码,然后将其粘贴到控制台中,如下所示:

flow = OAuth2WebServerFlow(o['installed']['client_id'], o['installed']['client_secret'], ga_real_scope, o['installed']['redirect_uris'][0])
authorize_url = flow.step1_get_authorize_url()
print ('Go to the following link in your browser: {0}'.format(authorize_url))
code = input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)

有没有一种方法可以在不使用硒的情况下实现自动化?你知道吗


Tags: installed数据脚本clientapi数据库url链接