簡體   English   中英

谷歌雲 API 403 - 權限不足

[英]Google Cloud API 403 - Insufficient Permission

我想從 Google Play 管理中心提取我們移動應用程序的報告數據。

根據此文檔,我們必須使用SignedJwtAssertionCredentials進行身份驗證。 經過一些錯誤和研究,文檔中的代碼片段似乎有點過時(因為SignedJWTAssertionCredentials不再可用)。 相反,我們嘗試了以下方法來自動下載報告:

from oauth2client.service_account import  ServiceAccountCredentials
from apiclient.discovery import build

scopes = ['https://www.googleapis.com/auth/analytics.readonly']
key_file_location = 'files/access_token/mykeyfile.json'

credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location, scopes)

cloud_storage_bucket = 'pubsite_prod_rev_123456789'
report_to_download = 'installs/installs_com.someapp.etc.etc_2021*'

storage = build('storage', 'v1', credentials=credentials)

print( storage.objects().get(bucket = cloud_storage_bucket,object = report_to_download).execute())

現在的問題是,我們收到以下錯誤消息:

Traceback (most recent call last):
  File "C:\Users\dev\dev\z_10_ext_google_play_store.py", line 30, in <module>
    print( storage.objects().get(bucket = cloud_storage_bucket,object = report_to_download).execute())
  File "D:\Software\Python\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\Software\Python\lib\site-packages\googleapiclient\http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://storage.googleapis.com/storage/v1/b/pubsite_prod_rev_123456789/o/installs%2Finstalls_com.someapp.etc.etc_2021%2A?alt=json returned "Insufficient Permission". Details: "[{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}]">

有人有想法嗎? 我們的服務帳戶甚至在游戲控制台中擁有管理員權限(這通常會太多..)

更新

正如 DaImTo 所指出的,我遺漏了一些作用域,這些作用域將我帶到了不同的 scope 定義行:

scopes = ['https://www.googleapis.com/auth/analytics.readonly', 'https://www.googleapis.com/auth/devstorage.read_only'

,'https://www.googleapis.com/auth/cloud-platform.read_only']

但我仍然收到一些錯誤,現在是因為缺少訪問令牌,這很奇怪,因為 .json 文件包含所有必要的東西:

Traceback (most recent call last):
  File "C:\Users\andre\Desktop\DAWSE\z_10_ext_google_play_store.py", line 33, in <module>
    print( storage.objects().get(bucket = cloud_storage_bucket,object = report_to_download).execute())
  File "D:\Sonstige Programme\Python\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\Sonstige Programme\Python\lib\site-packages\googleapiclient\http.py", line 923, in execute
    resp, content = _retry_request(
  File "D:\Sonstige Programme\Python\lib\site-packages\googleapiclient\http.py", line 191, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "D:\Sonstige Programme\Python\lib\site-packages\oauth2client\transport.py", line 159, in new_request
    credentials._refresh(orig_request_method)
  File "D:\Sonstige Programme\Python\lib\site-packages\oauth2client\client.py", line 749, in _refresh
    self._do_refresh_request(http)
  File "D:\Sonstige Programme\Python\lib\site-packages\oauth2client\client.py", line 785, in _do_refresh_request
    self.access_token = d['access_token']
KeyError: 'access_token'

您似乎正在使用objects.get方法

經過身份驗證的用戶必須具有 足夠的權限才能使用此方法。 首先,我會確保您的服務帳戶具有訪問權限。

之后我會檢查你的范圍你目前只加載 scope 用於谷歌分析 api。

scopes = ['https://www.googleapis.com/auth/analytics.readonly']

此 scope 不會授予您訪問谷歌雲存儲對象獲取方法的權限。 為此,您需要使用谷歌雲存儲范圍之一

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM