Google My Business API always return Invalid Requests

282 views Asked by At

I'm building an app that get all the google reviews from the connected user.

I want to use Google My Business API for that.

I have made all the prerequisites Google asked for, and I have activated the API in my project, as well as asked the user for the authorizations.

The Google My Business API being private, I couldn't find the gem for it on https://github.com/googleapis/google-api-ruby-client

So, following the steps described in this GitHub Issue, I generated the API in my project form this Discovery File.

The generated API is in my rails project in lib/google-apis-mybusiness_v4

In my Gemfile:

gem "google-apis-mybusiness_v4", path: "lib/google-apis-mybusiness_v4"

the code I tried (the user is connected successfully):

require "google/apis/mybusiness_v4"

#...
secrets = Google::APIClient::ClientSecrets.load("./code_secret_client.json")
authorizer = secrets.to_authorization
authorizer.update!(scope: "https://www.googleapis.com/auth/business.manage", access_token: user.token )

service = Google::Apis::MybusinessV4::MyBusinessService.new
service.authorization = authorizer

service.list_accounts #=> Google::Apis::ClientError: Invalid request

I showed list_account here but any function of MyBusinessService returns Google::Apis::ClientError: Invalid request

I also tried tu use some other google APIs, but fetching the gems from ruby-gem, and it works with the same code

Example:

#Gemfile
gem 'google-apis-mybusinessaccountmanagement_v1', '~> 0.1'

#code
require "google/apis/mybusinessaccountmanagement_v1"

secrets = Google::APIClient::ClientSecrets.load("./code_secret_client.json")
authorizer = secrets.to_authorization
authorizer.update!(scope: "https://www.googleapis.com/auth/business.manage", access_token: user.token )

service_management = Google::Apis::MybusinessaccountmanagementV1::MyBusinessAccountManagementService.new
service_management.authorization = authorizer

service_management.list_accounts(options: { authorization: authorizer }) #=> successfully lists all the accounts

(I don't know why I have to specify the authorization again in the options, but it only works that way. Also I tried service.list_accounts(options: { authorization: authorizer }) with the MyBusinessService list_accounts as well, same error, Google::Apis::ClientError: Invalid request )

This is the first time I've used a gem this way, so maybe I made mistakes that would explain the error I'm getting.

0

There are 0 answers