2

I created one service account with role big query admin.I am Using big query PHP API. Let me know if any other permission is required or not?

It gives me an error stating that the:

service account does not have bigquery.jobs.create permission.

I wanted to run a query on bigquery. Please help.

Following is my code:

     $service = new Google_Service_Bigquery($client);


    $query = new Google_Service_Bigquery_QueryRequest($client);
      $query->setQuery('SELECT * FROM [xxx:xxx.xxs] LIMIT 1000;');

      $jobs = $service->jobs;
      $response = $jobs->query($project_id, $query);

      // Do something with the BigQuery API $response data
      print_r($response)

;
ManmeetP
  • 801
  • 7
  • 17
samit
  • 63
  • 1
  • 1
  • 7

1 Answers1

1

I ran into this problem using the BQ library for nodejs.

It seems being signed into a user/service account via the CLI is not always enough. My service account was authenticated and had the correct permissions in the GCP SDK Shell, but I still got service account does not have bigquery.jobs.create permission..

I was able to fix this by simply adding the same service account details, using the client library methods. I used https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html.

In the case of nodejs, I just had to add

// Imports BigQuery library
const {BigQuery} = require('@google-cloud/bigquery');
// Create BQ Options - this object is what fixed the issue
const bqOptions = {};
bqOptions.projectId = '*your-project-name*';
bqOptions.keyFilename = '*Path-to-service-account-private-key*';
// Creates BQ client
const bq = new BigQuery(bqOptions);

I know you are using the PHP library, but I think the PHP equivalent would work the same.

DJ-ST
  • 129
  • 10