【问题标题】:Google Business Profile API readMaskGoogle Business Profile API 读取掩码
【发布时间】:2021-12-21 06:57:45
【问题描述】:

在我的发现 url 被弃用后,我不得不对我的代码进行一些更改,现在我收到了这个错误。

googleapiclient.errors.HttpError: https://mybusinessbusinessinformation.googleapis.com/v1/accounts/{*accountid*}/locations?filter=locationKey.placeId%3{*placeid*}&readMask=paths%3A+%22locations%28name%29%22%0A&alt=json 返回“请求包含无效参数。”。详细信息:“[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'read_mask', 'description': '提供的字段掩码无效'}] }]">

我正在尝试使用这个端点accounts.locations.list

我正在使用:

  • python 3.8
  • google-api-python-client 2.29.0

我当前的代码如下:

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()

从错误中,我尝试了很多字段掩码路径,但仍然不知道他们想要什么。 我尝试了 location.name, name, locations.name,locations.location.name 之类的方法,但没有成功。

我也尝试在不使用 FieldMask 类的情况下传递 readMask 参数并传递字符串和同样的问题。

因此,如果有人知道他们想要的 readMask 的格式是什么,那对我来说会很棒!

.

可以帮忙:

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

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

【问题讨论】:

    标签: python google-api google-client


    【解决方案1】:

    您没有正确设置 readMask。我在 Java 中完成了类似的任务,谷歌返回了结果。 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());              
                            } 
    

    --关于您所问的评论中的问题,这就是我对 placeId 的看法:

    【讨论】:

    • 这太疯狂了,我确定我已经用字符串尝试过了,今天它可以工作,但现在我有一个新问题 ='('field': 'filter', 'description': 'Unsupported filter field.' 但在他们说的发现端点过滤器是可选的,they provide exemple 所以我的网址看起来像这样accounts/{*account_id*}/locations?filter=locationKey.placeId%3D%22{*place_id*}%22&amp;readMask=name&amp;alt=json
    • 首先,现在无法从 locationKey.placeId 访问 placeId,这与 google mybusiness v4 有关,据我所知,存在名为元数据的对象。我不能在这里分享照片,所以我将编辑上面的回复。所以,我想说你所指的链接还没有更新。
    • 试试这个,我有结果,mybusinessbusinessinformation.googleapis.com/v1/accounts{The-account-ID}/locations?filter=distance(latlng, geopoint(xxx, yyyy))
    猜你喜欢
    • 1970-01-01
    • 2022-07-30
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多