Ebin K Baby
Ebin K Baby

Reputation: 1

Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested. - Google API

I am working on Google API. Created service account, and added client_id in workspace account with scope.(Domain-wide Delegation) Scope - https://www.googleapis.com/auth/business.manage Client ID - Numeric Value From Service Account Page

But still showing this error when I give, gmail account. If I give workspace account mail, it will work.

Domain Verification in APIs & Services ( Developer Console) Not completed.

enter image description here

Please look into this.

        $client = new \Google_Client();
        $client->setApplicationName("Google My Business");
        $client->setSubject('test***@gmail.com');
        $client->setAuthConfig('secret.json');
        $client->setApiFormatV2(2);
        $client->addScope("https://www.googleapis.com/auth/business.manage");
        $client->setAccessType('offline');
        $client->authorize();

        $service = new \Google_Service_MyBusiness($client);
        $result_accounts = $service->accounts->listAccounts()->getAccounts();
        $locations =  $service->accounts_locations->listAccountsLocations($result_accounts[0]['name']);
         dd($result_accounts);

Upvotes: 0

Views: 240

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117146

If you are trying to deligate to a user it must be a user on your domain

$client->setSubject('test***@gmail.com');

A standard gmail user can not be delegated to from your domain.

Upvotes: 0

Related Questions