google.auth.exceptions.refreserror:'无访问令牌。响应。'

发布于 2025-02-10 16:26:52 字数 3620 浏览 0 评论 0 原文

环境详细信息

  • OS类型和版本:
  • Python版本:3.9.0
  • PIP版本:22.0.4
  • Google-api-python-client 版本:2.48.0

description

hi,我在尝试时遇到了错误获取我们的移动应用程序的Google Play控制台报告(例如安装,错误等)。我首先尝试使用本手册,但似乎已经过时并且不起作用。因此,经过一番研究,我更改了类似于,它适合当前的Google API(请参见下面的代码段)。 我已经完成的步骤:

  1. 在“ console.cloud.google.com”上创建一个项目,
  2. 创建了服务帐户
  3. 创建的JSON密钥文件
  4. 邀请了play.google.com/console上的服务帐户,并给了他完整的管理权(通常“请参阅应用程序”信息并下载批量报告“应该足够)
  5. https://console.cloud.google.com/iam-admin/iam?authuser=1&project=myproject
  6. 等待24h,以确保没有错误由于同步左右。

(我匿名化了以下一些值)。

代码示例


from googleapiclient.discovery import build
from google.oauth2 import service_account

scopes = ['https://www.googleapis.com/auth/devstorage.read_only','https://www.googleapis.com/auth/cloud-platform.read_only']
key_file_location = 'files/access_token/mykeyfile.json'
cloud_storage_bucket = r'pubsite_prod_rev_00123456789'
report_to_download = 'installs/installs_com.my.app_202201_country.csv'

creds = service_account.Credentials.from_service_account_file(key_file_location,scopes=scopes)
service = build('storage','v1', credentials=creds)
print(service.objects().get(bucket = cloud_storage_bucket, object= report_to_download).execute())

堆栈跟踪

Traceback (most recent call last):
  File "C:\Users\myuser\project\z_10_ext_google_play_store.py", line 46, in <module>
    print(service.objects().get(bucket = cloud_storage_bucket, object= report_to_download).execute())
  File "D:\Programs\Python\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\Programs\Python\lib\site-packages\googleapiclient\http.py", line 923, in execute
    resp, content = _retry_request(
  File "D:\Programs\Python\lib\site-packages\googleapiclient\http.py", line 191, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "D:\Programs\Python\lib\site-packages\google_auth_httplib2.py", line 209, in request
    self.credentials.before_request(self._request, method, uri, request_headers)
  File "D:\Programs\Python\lib\site-packages\google\auth\credentials.py", line 133, in before_request
    self.refresh(request)
  File "D:\Programs\Python\lib\site-packages\google\oauth2\service_account.py", line 410, in refresh
    access_token, expiry, _ = _client.jwt_grant(
  File "D:\Programs\Python\lib\site-packages\google\oauth2\_client.py", line 199, in jwt_grant
    six.raise_from(new_exc, caught_exc)
  File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ('No access token in response.', {'id_token': 'eyJ...'})

我希望我能提供足够的信息,如果我犯了一个愚蠢的错误,我很抱歉。

Environment details

  • OS type and version:
  • Python version: 3.9.0
  • pip version: 22.0.4
  • google-api-python-client version: 2.48.0

Description

Hi, I'm running into an error when trying to fetch the Google Play Console reports of our mobile apps (such as installations, errors etc.). I first tried with this manual but it seems to be outdated and didn't work. So after some research I changed it similar to this one, that it fits to the current google api (see code snippet below).
Steps I have done:

  1. Created a project on "console.cloud.google.com"
  2. Created the service account
  3. Created the json key file
  4. Invited the service account on play.google.com/console and gave him full admin rights (normally "see app information and download bulk reports" should be enough)
  5. Added the role "Storage Object Viewer" to the Service account in https://console.cloud.google.com/iam-admin/iam?authuser=1&project=myproject
  6. waited for 24h to make sure there are no errors because of syncs or so.

(I anonymized some of the values below).

Code example


from googleapiclient.discovery import build
from google.oauth2 import service_account

scopes = ['https://www.googleapis.com/auth/devstorage.read_only','https://www.googleapis.com/auth/cloud-platform.read_only']
key_file_location = 'files/access_token/mykeyfile.json'
cloud_storage_bucket = r'pubsite_prod_rev_00123456789'
report_to_download = 'installs/installs_com.my.app_202201_country.csv'

creds = service_account.Credentials.from_service_account_file(key_file_location,scopes=scopes)
service = build('storage','v1', credentials=creds)
print(service.objects().get(bucket = cloud_storage_bucket, object= report_to_download).execute())

Stack trace

Traceback (most recent call last):
  File "C:\Users\myuser\project\z_10_ext_google_play_store.py", line 46, in <module>
    print(service.objects().get(bucket = cloud_storage_bucket, object= report_to_download).execute())
  File "D:\Programs\Python\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "D:\Programs\Python\lib\site-packages\googleapiclient\http.py", line 923, in execute
    resp, content = _retry_request(
  File "D:\Programs\Python\lib\site-packages\googleapiclient\http.py", line 191, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "D:\Programs\Python\lib\site-packages\google_auth_httplib2.py", line 209, in request
    self.credentials.before_request(self._request, method, uri, request_headers)
  File "D:\Programs\Python\lib\site-packages\google\auth\credentials.py", line 133, in before_request
    self.refresh(request)
  File "D:\Programs\Python\lib\site-packages\google\oauth2\service_account.py", line 410, in refresh
    access_token, expiry, _ = _client.jwt_grant(
  File "D:\Programs\Python\lib\site-packages\google\oauth2\_client.py", line 199, in jwt_grant
    six.raise_from(new_exc, caught_exc)
  File "<string>", line 3, in raise_from
google.auth.exceptions.RefreshError: ('No access token in response.', {'id_token': 'eyJ...'})

I hope that I provided enough information and I'm sorry in advance if I made a stupid mistake.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文