My Business
1.4K members online now
1.4K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

How to "build" a service

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi Team,

I'm trying to build a service that once a day gets all the new reviews of a +500 locations account using Python. I am trying to install it on a server to "cron it" once a day but, if I connect with another Google API, for instance, drive:

scopes = ['https://www.googleapis.com/auth/drive.metadata.readonly']
credentials = ServiceAccountCredentials.from_json_keyfile_name('service-account.json', scopes)
http_auth = credentials.authorize(Http())
drive = build('drive', 'v3', http=http_auth)

I can "build" the service object.

How could I do something similar with My Business API?

Thank you

David

1 Expert replyverified_user

Re: How to "build" a service

[ Edited ]
Google Employee
# 2
Google Employee

Hi @David C,

 

You should use the Google API Client Library for Python to handle all requests since all methods in the Google My Business API are included in the discovery document for the API. Please use the client libraries we provide when interacting with Google's OAuth 2.0 endpoints for the security implications of getting the implementation correct.

 

Please note that a one-time user consent is required for a service account to be able to access the Google My Business account and location data on behalf of a particular end user. The end users will have to log in with their Google Accounts to manually authorize the application during the OAuth 2.0 installed applications flow or using OAuth 2.0 Playground. This process needs to be done only once. When you prepare to make authorized API calls using the service account, you specify the user to impersonate by specifying the email address of the user account for access to their Google My Business data. If the end users have manually authorized the application, you should be able to access their Google My Business data. If the end users later want to revoke the application’s access to their Google My Business data, they can remove the authorized app from the Apps connected to your account page of their accounts.

 

Here is a code snippet for the Google API Client Library for Python that performs service account authentication:


import json

from httplib2 import Http

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build

client_email = '123456789000-abc123def456@developer.gserviceaccount.com'

scopes = ['https://www.googleapis.com/auth/plus.business.manage']

credentials = ServiceAccountCredentials.from_p12_keyfile(
  client_email, '/path/to/keyfile.p12', scopes=scopes)

delegated_credentials = credentials.create_delegated('user@example.org')

http = Http()
delegated_credentials.authorize(http)

response, content = http.request("https://mybusiness.googleapis.com/v3/accounts", "GET")
print content

We hope this solves your problem.

 

Thanks,

The Google My Business API team

Re: How to "build" a service

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Yash
I did a simple change, https://mybusiness.googleapis.com/v3/accounts instead of https://mybusiness.googleapis.com/v2/accounts and working perfectly.
Thank you very much
David