【问题标题】:How to bypass the browser authentication on calling google form API, which uses oauth2?如何在调用使用 oauth2 的谷歌表单 API 时绕过浏览器身份验证?
【发布时间】:2022-07-07 05:13:21
【问题描述】:

我想使用 pentaho 自动化从谷歌提取数据的过程,但在执行脚本期间,浏览器打开并要求选择 gmail 帐户进行身份验证,我在我的 python 代码中使用 OAuth 身份验证。问题在于它会造成障碍,并且需要人工干预来选择用于身份验证的帐户。

如何在 python 代码中避免这种情况,或者是否有另一种不用于浏览器身份验证的身份验证方法。因为在 google 文档中只说明了使用 oauth2 的身份验证。

这是我正在运行的代码:

from __future__ import print_function

from apiclient import discovery
from httplib2 import Http
from oauth2client import client, file, tools
from google.auth.transport.requests import Request  

SCOPES = "https://www.googleapis.com/auth/forms.responses.readonly"
DISCOVERY_DOC = "https://forms.googleapis.com/$discovery/rest?version=v1"

store = file.Storage('token.json')
creds = None
if not creds or creds.invalid:
    if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
    else:
            print("need to open browser for authentication")    
    flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = discovery.build('forms', 'v1', http=creds.authorize(
    Http()), discoveryServiceUrl=DISCOVERY_DOC, static_discovery=False)

# Prints the responses of your specified form:
form_id = '<form_id>'
result = service.forms().responses().list(formId=form_id).execute()
print(result)

这是在脚本执行期间打开的浏览器图像

enter image description here

【问题讨论】:

    标签: python authentication data-extraction google-forms-api


    【解决方案1】:

    这几天也一直在处理同样的问题......我发现很难理解为什么在我生成 API 密钥后谷歌必须寻求身份验证

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 2018-06-07
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 2012-12-13
      • 2015-08-15
      • 1970-01-01
      相关资源
      最近更新 更多