AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

Invalid request when using the findMatches method

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

Hello,

 

I'm using the ruby google client api but I can't seem to be able to make the findMatches method work.

 

My code looks like this:

 

 

find_matching_locations_request_object = Google::Apis::MybusinessV3::FindMatchingLocationsRequest.new(language_code: 'fr')
      
@service.find_account_location_matches(name, find_matching_locations_request_object) do |res, err| return err ? false : res end

 

And the API returns:

 

 

Sending HTTP post https://mybusiness.googleapis.com/v3/api:findMatches?
404
#<Hurley::Response POST https://mybusiness.googleapis.com/v3/api:findMatches == 404 (1579 bytes) 54ms>
Caught error Invalid request
Error - #<Google::Apis::ClientError: Invalid request>

 

Is it something related to the language code ? I couldn't find how to increase the log level to get more feedback on the error.

 

Also, what does the method's description mean when saying:

Finds all of the possible locations that are a match to the specified location. This operation is only valid if the location is unverified.

Will it raise an error if the location is verified ?

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Abdelkader B
October 2016

Re: Invalid request when using the findMatches method

Google Employee
# 2
Google Employee

Hi @Abdelkader B,

 

The POST request you send to the :findMatches endpoint via the Google My Business API finds and returns all of the possible locations on Google Maps, as indicated by the placeId in the LocationKey, that are a match to the specified location. The locations.findMatches operation is only valid if the location is unverified.

 

You will not invoke an InternalError if you send the POST request to the :findMatches endpoint for a verified location, as indicated by isVerified in the LocationState; however, you can only get back the matchTime field for this endpoint if the location is verified.

 

Please note that the Google API Client Library for Ruby is in alpha and support for this library should be directed to its Support page. Please also note that you can enable more detailed error messages in responses for the Google My Business API by adding an additional header to your requests when using the Google API Client Library for Ruby.

 

The following is a code snippet for a Ruby command-line application to find all of the possible locations on Google Maps that are a match to the specified location with Google API Client Library for Ruby via the Google My Business API:

require 'google/apis/mybusiness_v3'

require 'google/api_client/client_secrets'

require 'launchy'

require 'json'

 

client_secrets = Google::APIClient::ClientSecrets.load('client_secrets.json')

auth_client = client_secrets.to_authorization

auth_client.update!(

 :scope => 'https://www.googleapis.com/auth/plus.business.manage',

 :redirect_uri => 'urn:ietf:wg:oauth:2.0:oob'

)

 

refresh_token_available = File.exist?('.' + File.basename(__FILE__))

if !refresh_token_available

 auth_uri = auth_client.authorization_uri.to_s

 Launchy.open(auth_uri)

 puts 'Paste the code from the auth response page:'

 auth_client.code = gets

 auth_client.fetch_access_token!

 File.open('.' + File.basename(__FILE__), 'w') { |file| file.write(auth_client.refresh_token) }

else

 #If authorization has already been given and refresh token was saved previously, refresh the access token here.

 auth_client.refresh_token = File.read('.' + File.basename(__FILE__))

 auth_client.fetch_access_token!

end

 

# Build a service object for the Google My Business API

mybusiness_service = Google::Apis::MybusinessV3::MybusinessService.new

mybusiness_service.authorization = auth_client

 

# List all accounts for the authenticated user.

puts "List of accounts:"

list_accounts_response = mybusiness_service.list_accounts

list_accounts_response.accounts.each do |account|

 jj JSON.parse(account.to_json)

 puts

end

 

# For testing purposes, selects the very first account in the accounts array to list all locations.

puts "List of locations:"

list_locations_response = mybusiness_service.list_account_locations(list_accounts_response.accounts[0].name)

list_locations_response.locations.each do |location|

 jj JSON.parse(location.to_json)

 puts

end

 

# For testing purposes, selects the very first account in the accounts array to list all admins.

puts "List of admins:"

begin

 # Add this additional header to your requests to enable more detailed error messages in responses

 opts = Google::Apis::RequestOptions.new

 opts.header = { "X-GOOG-API-FORMAT-VERSION" => 2 }

 list_account_admins_response = mybusiness_service.list_account_admins(list_accounts_response.accounts[0].name, options: opts)

 list_account_admins_response.admins.each do |admin|

   jj JSON.parse(admin.to_json)

   puts

 end

rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e

 # display the system generated error message

 puts e.body

 puts

end

 

# For testing purposes, selects the very first location in the locations array to find all matches on Google Maps to the location.

puts "List of matches on Google Maps to the location:"

begin

 # Request message for MyBusiness.FindMatchingLocations.

 find_matching_locations_request = Google::Apis::MybusinessV3::FindMatchingLocationsRequest.new(language_code: "en", num_results: 5)

 # Add this additional header to your requests to enable more detailed error messages in responses

 opts = Google::Apis::RequestOptions.new

 opts.header = { "X-GOOG-API-FORMAT-VERSION" => 2 }

 find_matching_locations_response = mybusiness_service.find_account_location_matches(list_locations_response.locations[0].name, find_matching_locations_request, options: opts)

 find_matching_locations_response.matched_locations.each do |matched_location|

   jj JSON.parse(matched_location.to_json)

   puts

 end

 puts "matchTime: " + find_matching_locations_response.match_time

rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e

 # display the system generated error message

 puts e.body

 puts

end

 

Thanks,

Terry

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Abdelkader B
October 2016

Re: Invalid request when using the findMatches method

Google Employee
# 2
Google Employee

Hi @Abdelkader B,

 

The POST request you send to the :findMatches endpoint via the Google My Business API finds and returns all of the possible locations on Google Maps, as indicated by the placeId in the LocationKey, that are a match to the specified location. The locations.findMatches operation is only valid if the location is unverified.

 

You will not invoke an InternalError if you send the POST request to the :findMatches endpoint for a verified location, as indicated by isVerified in the LocationState; however, you can only get back the matchTime field for this endpoint if the location is verified.

 

Please note that the Google API Client Library for Ruby is in alpha and support for this library should be directed to its Support page. Please also note that you can enable more detailed error messages in responses for the Google My Business API by adding an additional header to your requests when using the Google API Client Library for Ruby.

 

The following is a code snippet for a Ruby command-line application to find all of the possible locations on Google Maps that are a match to the specified location with Google API Client Library for Ruby via the Google My Business API:

require 'google/apis/mybusiness_v3'

require 'google/api_client/client_secrets'

require 'launchy'

require 'json'

 

client_secrets = Google::APIClient::ClientSecrets.load('client_secrets.json')

auth_client = client_secrets.to_authorization

auth_client.update!(

 :scope => 'https://www.googleapis.com/auth/plus.business.manage',

 :redirect_uri => 'urn:ietf:wg:oauth:2.0:oob'

)

 

refresh_token_available = File.exist?('.' + File.basename(__FILE__))

if !refresh_token_available

 auth_uri = auth_client.authorization_uri.to_s

 Launchy.open(auth_uri)

 puts 'Paste the code from the auth response page:'

 auth_client.code = gets

 auth_client.fetch_access_token!

 File.open('.' + File.basename(__FILE__), 'w') { |file| file.write(auth_client.refresh_token) }

else

 #If authorization has already been given and refresh token was saved previously, refresh the access token here.

 auth_client.refresh_token = File.read('.' + File.basename(__FILE__))

 auth_client.fetch_access_token!

end

 

# Build a service object for the Google My Business API

mybusiness_service = Google::Apis::MybusinessV3::MybusinessService.new

mybusiness_service.authorization = auth_client

 

# List all accounts for the authenticated user.

puts "List of accounts:"

list_accounts_response = mybusiness_service.list_accounts

list_accounts_response.accounts.each do |account|

 jj JSON.parse(account.to_json)

 puts

end

 

# For testing purposes, selects the very first account in the accounts array to list all locations.

puts "List of locations:"

list_locations_response = mybusiness_service.list_account_locations(list_accounts_response.accounts[0].name)

list_locations_response.locations.each do |location|

 jj JSON.parse(location.to_json)

 puts

end

 

# For testing purposes, selects the very first account in the accounts array to list all admins.

puts "List of admins:"

begin

 # Add this additional header to your requests to enable more detailed error messages in responses

 opts = Google::Apis::RequestOptions.new

 opts.header = { "X-GOOG-API-FORMAT-VERSION" => 2 }

 list_account_admins_response = mybusiness_service.list_account_admins(list_accounts_response.accounts[0].name, options: opts)

 list_account_admins_response.admins.each do |admin|

   jj JSON.parse(admin.to_json)

   puts

 end

rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e

 # display the system generated error message

 puts e.body

 puts

end

 

# For testing purposes, selects the very first location in the locations array to find all matches on Google Maps to the location.

puts "List of matches on Google Maps to the location:"

begin

 # Request message for MyBusiness.FindMatchingLocations.

 find_matching_locations_request = Google::Apis::MybusinessV3::FindMatchingLocationsRequest.new(language_code: "en", num_results: 5)

 # Add this additional header to your requests to enable more detailed error messages in responses

 opts = Google::Apis::RequestOptions.new

 opts.header = { "X-GOOG-API-FORMAT-VERSION" => 2 }

 find_matching_locations_response = mybusiness_service.find_account_location_matches(list_locations_response.locations[0].name, find_matching_locations_request, options: opts)

 find_matching_locations_response.matched_locations.each do |matched_location|

   jj JSON.parse(matched_location.to_json)

   puts

 end

 puts "matchTime: " + find_matching_locations_response.match_time

rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e

 # display the system generated error message

 puts e.body

 puts

end

 

Thanks,

Terry

Invalid request when using the findMatches method

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thank you @Terry W for the detailed response, it helped me understand what I was doing wrong.

 

As a related question, will the API provide a way to list all the locations based on a given search string (Like in the Google My Business interface. i.e. "MY_BUSINESS_REAL_NAME":findMatches) in the future ?

 

Thank you in advance,

 

Re: Invalid request when using the findMatches method

Google Employee
# 4
Google Employee

Hi @Abdelkader B,

 

We are aware of your feature request for listing all matched locations under the specified account based on a given search term. We’ll keep your scenario in mind as we’re working on the next release and announce new features of the Google My Business API when they become available on both this board and the Google Developers site. Please stay tuned and thanks for your patience!

 

For the time being, you can list all locations for the specified account and use filters to limit the results that are returned.

 

Thanks,

The Google My Business API team

Invalid request when using the findMatches method

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi @Terry W,

 

Thank you for the feedback.

 

Actually, what I was talking about is the ability to perform a global search to get all the verified locations that match a certain keyword, not specifically in my own account. A good scenario where it would be very helpful, is to check if the location already exist elsewhere before even creating my own location through the API.

 

Thank you,

 

Re: Invalid request when using the findMatches method

Google Employee
# 6
Google Employee

Hi @Abdelkader B,

 

Your requested feature already exists as Place Search using the Google Places API. Please direct your questions for the Google Places API to its Community and Support page.

 

Please note that it’s not possible to find out if a location that’s connected to/appears on Google Maps with a placeId has a verified owner if you don’t create a new location in Google My Business either via the UI or the API and try to verify this new location via the Google My Business UI. During the verification process, you’ll be notify if someone else verified your business and what you can do to fix it and activate your listing.

 

For more information about your listing status, please check out this article in the Google My Business Help Center.

 

Thanks,

Terry