我需要从 Google Colab 内的 Python 生成access_token一些特定范围的文件['https://www.googleapis.com/auth/bigquery', 'https://www.googleapis.com/auth/cloud-platform']。
默认情况下,Google Colab 在colabtools内部提供了一个功能来对用户进行身份验证。
from google.colab import auth
auth.authenticate_user()
print('Authenticated')
Run Code Online (Sandbox Code Playgroud)
但生成的凭证文件包含固定范围的列表,不包括我需要的范围。
import os
with open(os.environ['GOOGLE_APPLICATION_CREDENTIALS']) as f:
print(f.read())
Run Code Online (Sandbox Code Playgroud)
...
"scopes": [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/appengine.admin",
"https://www.googleapis.com/auth/accounts.reauth",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/userinfo.email"
],
...
Run Code Online (Sandbox Code Playgroud)
我尝试使用google.auth.Credentials类和google.oauth2.Credentialsgoogle-auth类通过库生成有效的凭据令牌。我可以生成类的有效实例,但是当我检查令牌时,它是“无”。enter code here
有没有办法access_token通过 Python 生成对 Google API 有效的自定义范围?
谢谢!
google-api access-token oauth-2.0 google-api-python-client google-colaboratory