0

I'm doing a request with the google api library and trying to download some report to automate the download and import to our system. However I'm running into issues. The error code I'm getting :

Google\Cloud\Core\Exception\ServiceException: { "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message": "service-worker@service-worker.iam.gserviceaccount.com does not have storage.objects.list access to pubsite_prod_rev_." } ], "code": 403, "message": "service-worker@service-worker.iam.gserviceaccount.com does not have storage.objects.list access to pubsite_prod_rev_." } } in D:\USER\Web\Directory\tools\vendor\google\cloud\Core\src\RequestWrapper.php on line 263

I've tried adding permisions to the pubsite_prod_dev directory I'm trying to access, however I'm getting another error, even though I'm the admin :

You don't have permission to view this bucket's metadata. Contact the bucket owner to grant you the "storage.buckets.get" and "storage.buckets.getIamPolicy" permissions.

I know about the gsutil tool, and I used it successfully, the issue is that I can't use it in our tooling server because the hosting provider denied us this software (Using managed hosting). So I'm stuck with trying to make the API libraries work. Any good solutions to this? I've already tried all kinds of libraries and code found in github, however nothing seems to be working, or is outdated and the libraries are not deprecated. .. My code:

<?php

require 'vendor/autoload.php';

use Google\Cloud\Storage\StorageClient;

$client  = new StorageClient([
    'scopes' => [StorageClient::READ_ONLY_SCOPE],
    'keyFile' => json_decode(file_get_contents('./client_secret.json'), true)
]);

$bucket = $client->bucket('pubsite_prod_rev_<code>');

foreach ($bucket->objects(['prefix' => 'sales/']) as $object) {
    print_r($object->name());
}

$file = $bucket->object('salesreport_201809.zip');
$file->downloadToFile();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
PaaPs
  • 373
  • 1
  • 4
  • 18

1 Answers1

0

This answer comes maybe to late. I had the same issue and remembered a sentence somwhere in the google docs stating that users who have permissions to the reports inside the Google Play Console also have access to the bucket where these reports are stored.

So the trick is to add the service account email (which you created to gain access to the cloud api with the StorageClient) to the Users inside Google Play Console.

chris
  • 1