I have to use the Google My Business APIs. The API itself look quite easy to use but i have a hard time with the credentials/connection.
I need to connect server side (in a Ruby/Rails job). All I see in the doc is the use of OAuth where you need a browser with a redirect URL...which is not what I want. I need a more "classic way" to connect to the APIs, where i can store the credentials or the APIs secret keys or whatever to my Rails secrets or in an ENV variable and that's it.
I've heard about using a "service account" with JWT token. But cannot find any easy/simple example. Is it the good way to do it ?
I also found this gem: https://github.com/googleapis/google-auth-library-ruby but don't know how to use it.
A simple Ruby step by step exemple would be welcome.
Thanks!
EDIT -->
I was able to get an access_token like this (with a service account).
Using the google-auth-library-ruby gem.
Now i have to find how to call APIs with it.
scope = 'https://www.googleapis.com/auth/business.manage'
authorizer = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open('config/xxx-8f824909xx39e8b.json'), scope: scope)
token = authorizer.fetch_access_token!
puts "---------->" + token.inspect
It's not possible to user a service account to use the Google my business API. Even if it's not specified in the docs (they even say you can use it). Unfortunately who have to use oAuth...
So if you don't want any user interaction to connect and validate the oAuth connection here is how to do it.
You have to connect once with the account (with OAuth 2.0 Playground from Google developer for example). And then you can have a refresh token, then you should store the refresh token for future use so you can obtain an access token to call the APIs. Once the access token expires your application should use the refresh token to obtain a new access token. Hope it helps.