google apiclient php vison 403 Request had insufficient authentication scopes -


trying use google vision api having following error:

error calling post https://vision.googleapis.com/v1/images:annotate: (403) request had insufficient authentication scopes. <

i using laravel in server not google (cloudways) , using google/apiclient instaleld via composer.

i have similar code google calendar information , works charm.

this code :

//i have google.php uner app/config information  $client_id = config::get('google.client_id');  $service_account_name = config::get('google.service_account_name');  $key_file_location =config::get('google.key_file_location');// base_path() .    $this->client = new \google_client();  $this->client->setapplicationname("my webapp");  /* if have access token */  if (cache::has('service_token')) {  $this->client->setaccesstoken(cache::get('service_token'));  }  $key = file_get_contents($key_file_location);  //in documentation have read talk scope   $scopes = array(  'https://www.googleaipis.com/auth/cloud-platform'   );   $cred = new \google_auth_assertioncredentials(  $service_account_name,  $scopes,  $key  );   $this->client->setassertioncredentials($cred);  if ($this->client->getauth()->isaccesstokenexpired()) {  $this->client->getauth()->refreshtokenwithassertion($cred);  }  cache::forever('service_token', $this->client->getaccesstoken());  $this->service = new \google_service_vision($this->client);  //i have dd(service , client) , looks including scope  $body = new \google_service_vision_batchannotateimagesrequest;   $feature = new \google_service_vision_feature();  $feature->setmaxresults(100);  $feature->settype("text_detection");   $src = new \google_service_vision_imagesource();  $src->setgcsimageuri("gs://cmrjb/recipts/gas receipt.jpg");  $image = new \google_service_vision_image();  $image->setsource($src);   $payload = new \google_service_vision_annotateimagerequest();  $payload->setfeatures($feature);  $payload->setimage($image);  $body->setrequests([$payload]);   dd( $this->service->images->annotate($body)); 

i have tried , dont see doing wrong.

any pointer great!!


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -