Google Business Profile API调用accounts.locations.list出现read_mask无效400错误
你遇到的报错是read_mask参数的传值格式和字段路径不符合接口要求,修正方法如下:
错误原因
- 该接口不需要传入
FieldMask类实例,直接传入逗号分隔的字段名字符串即可,你传入的FieldMask对象会被序列化为包含paths结构的内容,和接口要求的read_mask格式不匹配。 - 你使用的
locations(name)这类路径写法错误,accounts.locations.list接口的readMask只需要指定单条Location资源下的字段名,不需要额外套外层的locations结构。
正确代码示例
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") outputLocation = googleAPI.service.accounts().locations().list( parent="accounts/{*id*}", filter=f"locationKey.placeId={google_place_id}", # 直接写需要返回的Location资源字段,多个字段用英文逗号分隔 readMask="name" ).execute()
如果需要同时返回多个字段,比如location的名称、地址、营业时间,直接按如下格式写即可:readMask="name,title,address,regularHours"
内容的提问来源于stack exchange,提问作者ag7-alexis
相关产品推荐
相关产品推荐

