ag7-alexis
ag7-alexis

Reputation: 123

Google Business Profile API readMask

After the deprecation of my discovery url, I had to make some change on my code and now I get this error.

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{*accountid*}/locations?filter=locationKey.placeId%3{*placeid*}&readMask=paths%3A+%22locations%28name%29%22%0A&alt=json returned "Request contains an invalid argument.". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'read_mask', 'description': 'Invalid field mask provided'}]}]">

I am trying to use this end point accounts.locations.list

I'm using :

My current code look likes :

from google.protobuf.field_mask_pb2 import FieldMask

googleAPI = GoogleAPI.auth_with_credentials(client_id=config.GMB_CLIENT_ID,
                                                client_secret=config.GMB_CLIENT_SECRET,
                                                client_refresh_token=config.GMB_REFRESH_TOKEN,
                                                api_name='mybusinessbusinessinformation',
                                                api_version='v1',
                                                discovery_service_url="https://mybusinessbusinessinformation.googleapis.com/$discovery/rest")

field_mask = FieldMask(paths=["locations(name)"])
outputLocation = googleAPI.service.accounts().locations().list(parent="accounts/{*id*}",
                                                                           filter="locationKey.placeId=" + google_place_id,
                                                                           readMask=field_mask
                                                                           ).execute()

From the error, i tried a lot of fieldmask path and still don't know what they want. I've tried things like location.name, name, locations.name, locations.location.name and it did'nt work.

I also try to pass the readMask params without use the FieldMask class with passing a string and same problem.

So if someone know what is the format of the readMask they want it will be great for me !

.

Can help:

https://www.youtube.com/watch?v=T1FUDXRB7Ns

https://developers.google.com/google-ads/api/docs/client-libs/python/field-masks

Upvotes: 4

Views: 8134

Answers (2)

luvai
luvai

Reputation: 31

As other people said you before, the readmask is not set correctly. Here Google My Business Information api v1 you can see:

"This is a comma-separated list of fully qualified names of fields"

and here Google Json representation you can see the field. With this, I tried this

read_mask = "name,title"

and it worked for me, hope this work for you too.

Upvotes: 3

Shila Mosammami
Shila Mosammami

Reputation: 1077

You have not set the readMask correctly. I have done a similar task in Java and Google returns the results. readMask is a String type, and what I am going to provide you in the following line includes all fields. You can omit anyone which does not serve you. I am also writing the request code in Java, maybe it can help you better to convert into Python.

String readMask="storeCode,regularHours,name,languageCode,title,phoneNumbers,categories,storefrontAddress,websiteUri,regularHours,specialHours,serviceArea,labels,adWordsLocationExtensions,latlng,openInfo,metadata,profile,relationshipData,moreHours";
MyBusinessBusinessInformation.Accounts.Locations.List request= mybusinessaccountLocations.accounts().locations().list(accountName).setReadMask(readMask);
    ListLocationsResponse Response = request.execute();
List<Location>= Response.getLocations();
while (Response.getNextPageToken() != null) {
                            locationsList.setPageToken(Response.getNextPageToken());
                            Response=request.execute();
                            locations.addAll(Response.getLocations());              
                        } 

-- about the question in the comment you have asked this is what I have for placeId: enter image description here

Upvotes: 7

Related Questions