So i have this code which i want to request for the table from google cloud BigQuery in Laravel 8 and i have already create a service account in my Google CLoud as well as made a key and got the json file with all the details of the Bigquery. When i call the query it doesnt go through and ask me for the permission error as follows
{ "error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ { "message": "Invalid Credentials", "domain": "global", "reason": "authError", "location": "Authorization", "locationType": "header" } ], "status": "UNAUTHENTICATED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "ACCESS_TOKEN_EXPIRED", "domain": "googleapis.com", "metadata": { "method": "google.cloud.bigquery.v2.JobService.InsertJob", "service": "bigquery.googleapis.com" } } ] } }
This is my controller
error_log('hello');
$bigQuery = new BigQueryClient([
'keyFile' => json_decode(file_get_contents(base_path() . env('GOOGLE_APPLICATION_CREDENTIALS', "env path not set")), true)
]);
// $date = str_replace("-", "", $req->date);
// Run a query and inspect the results.
$queryJobConfig = $bigQuery->query(
'SELECT event.value.string_value as Screen, count(*) as ViewCount,
FROM `rtiapp-4593f.analytics_353940796.*`,
UNNEST(event_params) as event
WHERE event.key = "firebase_screen"
GROUP BY event.value.string_value
ORDER BY ViewCount DESC LIMIT 20'
);
error_log('hi');
$queryResults = $bigQuery->runQuery($queryJobConfig);
error_log('hi');
error_log('queryResults');
error_log( $queryResults);
$info = $queryResults->info();
$results = $info['rows'];
error_log($results);
$schema = $info['schema'];
$fields = $schema['fields'];
error_log($info);
May i know where i am going wrong please. Any help would be appreicated.
I tried many things including making a new service account and put that json there and aslo using gcloud login but still no luck.