【问题标题】:Event is required error when creating Call-To-Action Post on Google My Business在 Google 我的商家上创建号召性用语帖子时需要事件错误
【发布时间】:2022-11-10 04:34:15
【问题描述】:

我有以下代码来创建一个新的呼吁采取行动发布 Google 我的商家位置信息,如下所示:

const { google } = require('googleapis');

let locationURL = `https://mybusiness.googleapis.com/v4/accounts/${accountId}/locations/${locationId}/localPosts`

let requestBody = {
    "languageCode": "en-US",
    "summary": "Test Call to action Post",
    "callToAction": {
        "actionType": "SIGN_UP",
        "url": "http://www.example.com",
    },
    "topicType": "OFFER"
}

let googleOAUTH2Client = new google.auth.OAuth2(process.env.GOOGLE_APP_CLIENT_ID,
                           process.env.GOOGLE_APP_CLIENT_SECRET);
 googleOAUTH2Client.setCredentials(credentials); //Credentials code redacted
    
try {
    let locationRes = await googleOAUTH2Client.request({
        url: locationUrl,
        method: 'POST',
        body: JSON.stringify(requestBody)
    });
    let { data } = locationRes;
    console.log(`ResponseData=${data, null, 2}`);
} catch (e) {
    let err = e?.response?.data
    console.log(JSON.stringify(err, null, 2));
}

但我一直得到的只是下面的错误消息:

{
    "error": {
        "code": 400,
        "message": "Request contains an invalid argument.",
        "errors": [
            {
                "message": "Request contains an invalid argument.",
                "domain": "global",
                "reason": "badRequest"
            }
        ],
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
                "errorDetails": [
                    {
                        "code": 2,
                        "field": "event",
                        "message": "event is required"
                    }
                ]
            }
        ]
    }
}

这让我想知道。为什么号召性用语帖子需要事件? Docs 从未在示例代码中提及这一点。

我该如何解决这个问题?

【问题讨论】:

    标签: node.js google-api google-api-nodejs-client google-my-business-api google-my-business


    【解决方案1】:

    为主题类型EVENTOFFER 添加event(参见event)。

    您引用的Docs 似乎不完整。

    谷歌APIs Explorer(永远)是你的朋友。

    搜索“我的业务”以获取Business Profile APIs

    然后localPost 是您用来查看权威文档的方法。

    请求正文是 LocalPost 类型,这描述了 event 与上述要求:

    事件信息。主题类型 EVENT 和 OFFER 是必需的。

    Google 为以下应用提供 SDK(称为“库”)全部它以多种语言提供服务,包括 Node.js。对于业务资料 API,您需要使用 Node.js API Client Library

    【讨论】:

      【解决方案2】:

      对于那些仍在寻找此类错误答案的人,以下是您的有效负载参数的结构:

      payload: JSON.stringify({
          "languageCode": "en-US",
          "summary": "Test Call to action Post",
          "callToAction": {
            "actionType": "SIGN_UP",
            "url": "http://www.example.com"
          },
          "event": {
            "title": "testing",
            "schedule": {
              "startDate": {
                "year": 2022,
                "month": 11,
                "day": 01
              },
              "startTime": {
                "hours": 05,
                "minutes": 00,
                "seconds": 00,
                "nanos": 00
              },
              "endDate": {
                "year": 2022,
                "month": 11,
                "day": 05
              },
              "endTime": {
                "hours": 10,
                "minutes": 00,
                "seconds": 00,
                "nanos": 00
              }
            }
          },
          "topicType": "OFFER"
        })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-24
        • 2014-05-25
        • 1970-01-01
        • 2014-10-26
        • 2021-03-07
        • 1970-01-01
        • 1970-01-01
        • 2014-05-05
        相关资源
        最近更新 更多