How to Authenticate, fetch google my business api accounts locations and reviews?

577 Views Asked by At

I want to fetch google my business location and their reviews by using google my business api with Service Accounts as authentication method.

google my business api is enabled google my business account api is enabled google my business information is enabled

code:

    const auth = new google.auth.GoogleAuth({
      keyFile: <service account json key path>,
      scopes: [
        'https://www.googleapis.com/auth/business.manage',
        'https://www.googleapis.com/auth/plus.business.manage',
      ],
    });
    const client = await auth.getClient();
     const url =
        'https://mybusinessaccountmanagement.googleapis.com/v1/accounts';
      const res = await client.request({ url });
      console.log(res.data);

response:

{
  accounts: [
    {
      name: 'accounts/<account number>',
      accountName: <service account email>,
      type: 'PERSONAL',
      verificationState: 'UNVERIFIED',
      vettedState: 'NOT_VETTED'
    }
  ]
}

then when i try to fetch locations, it return 404 with readMask param and empty object with readMask

 const locationsUrl = `https://mybusiness.googleapis.com/v1/accounts/<account number>/locations?readMask=name`;
        const locationsRes = await client.request({ url: locationsUrl });

i want to fetch all my business locations and their reviews. Please help

i have gone through the documentation of both v1 and v4. either it returns 404 or no empty response.

1

There are 1 best solutions below

0
On

How exactly are you expecting a service account to have access to GBP resources like location groups, locations and reviews? In order to have access to them, a Google account (i.e. a Workspace account or a private Gmail account) needs to exist and have manager or owner permissions.

For requesting the data that you seek, you need to authenticate using that Google account.