schulzefelix / laravel-search-console

A Laravel package to retrieve data from Google Search Console
MIT License
47 stars 24 forks source link

Trying to use with service_account, failures #11

Closed rodericktech closed 6 years ago

rodericktech commented 6 years ago

I figured out the issue, my apologies

vesper8 commented 3 years ago

@rodericktech I know it's been a few years but I'm struggling to use this with a service account as well. Could you possible explain what you did to get it working?

I've created a service account already and changed the default auth_type in the configuration file to use my service account.

In a test command I'm trying this:

$searchConsole = app(SearchConsole::class);
$sites = $searchConsole->listSites();

And getting this error

Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information

  at vendor/google/auth/src/ApplicationDefaultCredentials.php:189
    185▕             $creds = new GCECredentials(null, $anyScope, null, $quotaProject);
    186▕         }
    187▕
    188▕         if (is_null($creds)) {
  ➜ 189▕             throw new DomainException(self::notFound());
    190▕         }
    191▕         if (!is_null($cache)) {
    192▕             $creds = new FetchAuthTokenCache($creds, $cacheConfig, $cache);
    193▕         }

And I'm just lost as to what's wrong

vesper8 commented 3 years ago

I was able to get it to work by adding this line above my calls

putenv(sprintf('GOOGLE_APPLICATION_CREDENTIALS=%s', config('search-console.connections.service_account.application_credentials')));

Though I feel like there was probably a better way