ag7*_*xis 3 python google-api google-client
在我的发现 url 被弃用后,我必须对我的代码进行一些更改,现在我收到此错误。
googleapiclient.errors.HttpError:<请求https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{*accountid*}/locations?filter=locationKey.placeId%3{*placeid*}&readMask=paths%3A+时出现 HttpError 400 %22locations%28name%29%22%0A&alt=json返回“请求包含无效参数。”。详细信息:“[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'read_mask', 'description': '提供的字段掩码无效'}] }]">
我正在尝试使用这个端点accounts.locations.list
我在用着 :
我当前的代码如下所示:
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()
Run Code Online (Sandbox Code Playgroud)
从错误中,我尝试了很多fieldmask路径,但仍然不知道他们想要什么。我尝试过诸如location.name、name、locations.name、locations.location.name 等操作,但没有成功。
我还尝试传递 readMask 参数,而不使用 FieldMask 类来传递字符串和相同的问题。
因此,如果有人知道他们想要的 readMask 的格式是什么,这对我来说会很棒!
。
可以帮助:
https://www.youtube.com/watch?v=T1FUDXRB7Ns
https://developers.google.com/google-ads/api/docs/client-libs/python/field-masks
您没有正确设置 readMask。我在 Java 中完成了类似的任务,Google 返回了结果。readMask 是一个 String 类型,我将在下面的行中为您提供包括所有字段的内容。您可以忽略任何不为您服务的人。我也在用Java编写请求代码,也许它可以帮助你更好地转换为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());
}
Run Code Online (Sandbox Code Playgroud)
-- 关于您在评论中提出的问题,这就是我对 placeId 的看法:

| 归档时间: |
|
| 查看次数: |
6416 次 |
| 最近记录: |