0

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.

Aquen
  • 267
  • 1
  • 2
  • 16
  • This error is commonly seen when you haven't included the proper values in your `scopes` variable. – weezilla Jul 05 '22 at 00:35
  • Hmm, interesting. But I thought that the two scopes in my code are enough. Don't have any clue which additional might be missing. – Aquen Jul 05 '22 at 07:12
  • You may need to add a permission to the service account to get buckets. There are several ways of adding this permission, but you can first test with the admin permission. https://serverfault.com/questions/958800/service-account-does-not-have-storage-buckets-get-access-to-bucket – weezilla Jul 05 '22 at 22:57
  • I checked you link at serverfault, but all the roles discussed over there are already part of the one for my service account since I tried it. – Aquen Jul 08 '22 at 05:26

0 Answers0