AccessTokenRefreshError: invalid_scope

Dav*_*tos 1 cron google-app-engine oauth-2.0

我正在尝试用 Cron.yaml 做一些事情我的 cron 工作正常,但身份验证没有。

在本地主机我使用这个:

from oauth2client.appengine import AppAssertionCredentials

    storage_credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/storage')
storage_http = storage_credentials.authorize(httplib2.Http())
storage_service = build("storage", "v1", http=storage_http)
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我在 GAE 中部署它时,这不起作用。

我找到了一个解决方案:

from oauth2client.client import SignedJwtAssertionCredentials

storage_credentials = SignedJwtAssertionCredentials(
  "463239370591-kvr7qpa2k5ee5jgdjgmk9ohc3ao3gve5@developer.gserviceaccount.com", key,
  scope=("https://www.googleapis.com/auth/storage")
)
storage_http = storage_credentials.authorize(httplib2.Http())
storage_service = build("storage", "v1", http=storage_http)
Run Code Online (Sandbox Code Playgroud)

使用此代码我有一个错误:

AccessTokenRefreshError: invalid_scope: https://www.googleapis.com/auth/storage不是有效的范围。

有人可以解释一下吗?

编辑

同时我用同样的方式到https://www.googleapis.com/auth/bigquery也没有问题!

Pat*_*ice 5

取自Google Cloud Storage 身份验证的文档,您似乎需要以下范围之一:

https://www.googleapis.com/auth/devstorage.read_only

https://www.googleapis.com/auth/devstorage.read_write

https://www.googleapis.com/auth/devstorage.full_control
Run Code Online (Sandbox Code Playgroud)

取决于你想做什么。您需要确保在您的控制台中启用了 API,并且还需要使用 Cloud Storage JSON API :)