0

I want to use a Google My Business API to search and manage the businesses of our clients using my organization account detail.

I want to use API as an Agency as I want to manage our clients' businesses.

I've submitted the API access form and got confirmation to use the APIs. Also, I've generated the OAuth credentials and service-account in the same account.

But as per the GMB API document, we need to pass an access token in order to access an API.

I've reviewed the authentication process using OAuth and service accounts. As per my requirement, I want to generate access token at the back end side directly from my NodeJS server code without user interaction.

I want to use my account detail to use APIs so need to get permission from the user as I do not need any user information.

I've tried the following for use as a service-account but it returns an error.

const keys = require("./config/gmb.json");
const {OAuth2Client,GoogleAuth,JWT} = require('google-auth-library');
const client = new JWT({
   email: keys.client_email,
   key: keys.private_key,
   scopes: ['https://www.googleapis.com/auth/business.manage'],
});
console.log(client.credentials);  // It returns refresh_token=jwt-placeholder, expiry_date=1
const tokenInfo = await client.getTokenInfo(client.credentials.access_token); // It returns Error: invalid_token 

So anyone has an idea on this. Your help will appreciatable.

Keyur Chavda-kc1994
  • 977
  • 1
  • 11
  • 22
  • What error are you getting @kc1994 – Xcode Oct 07 '20 at 15:12
  • Hi @Xcode, please check my question, I've mentioned an error in a code block as a comment. Actually, I want to use GMB API to manage our clients' businesses through our application but I do not know how to make the OAuth process for that as I want to add business at the back end side without user interaction. – Keyur Chavda-kc1994 Oct 08 '20 at 07:41

1 Answers1

0

I got the answer to my question.

If we want to get the access token of any user account first we need to prompt the user for OAuth and once the user gives its account permission we need to store the user account details with refresh-token that google will give once we complete the user OAuth process.

Now, whenever we need the access token of any user account we can get it using the refresh token of user account details that have stored after completing the OAuth process.

Note: The refresh token can expire if the user changes his account password or some details which affect user privacy.

I've done this OAuth process and getting the access token of a user in NodeJs.

Keyur Chavda-kc1994
  • 977
  • 1
  • 11
  • 22