在 Google 上创建帖子

您可通过 Google My Business API 在 Google 搜索中创建多个类别(例如报道、活动信息和优惠信息)的帖子。

本教程介绍了如何执行以下操作:

准备工作

在使用 Google My Business API 之前,您需要注册您的应用并获取 OAuth 2.0 凭据。

如需详细了解如何使用 Google My Business API,请参阅基本设置

包含活动信息的帖子

发布帖子,告知客户您的商家即将推出的下一个活动。您发布的包含活动信息的帖子应以醒目方式显示开始和结束日期及时间。

如需将帖子发布到与用户关联的账号,请使用 accounts.locations.localPosts API。

如需为经过身份验证的用户创建帖子,请使用以下代码:

HTTP
$ POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts
{
  "languageCode": "en-US",
  "summary": "Come in for our spooky Halloween event!",
  "event": {
    "title": "Halloween Spook-tacular!",
    "schedule": {
        "startDate": {
            "year": 2017,
            "month": 10,
            "day": 31,
          },
          "startTime": {
              "hours": 9,
              "minutes": 0,
              "seconds": 0,
              "nanos": 0,
          },
          "endDate": {
            "year": 2017,
            "month": 10,
            "day": 31,
          },
          "endTime": {
              "hours": 17,
              "minutes": 0,
              "seconds": 0,
              "nanos": 0,
          },
    }
  },
  "media": [
    {
      "mediaFormat": "PHOTO",
      "sourceUrl": "https://www.google.com/real-image.jpg",
    }
  ],
  "topicType": "EVENT"
}

包含号召性用语的帖子

包含号召性用语的帖子带有一个按钮。“号召性用语”按钮上的文本由帖子的 actionType 字段来决定。该按钮会添加一个指向用户提供的网址的链接。

如需创建包含“号召性用语”按钮的帖子,请使用以下代码:

HTTP
$ POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts
{
  "languageCode": "en-US",
  "summary": "Order your Thanksgiving turkeys now!!",
  "callToAction": {
    "actionType": "ORDER",
    "url": "http://google.com/order_turkeys_here",
  },
  "media": [
    {
      "mediaFormat": "PHOTO",
      "sourceUrl": "https://www.google.com/real-turkey-photo.jpg",
    }
  ],
  "topicType": "OFFER"
}

操作类型

号召性用语帖子可以使用不同的操作类型,这也会决定号召性用语帖子的类型。

以下是受支持的号召性用语类型:

操作类型
BOOK 创建帖子,提示用户预约服务、桌位或进行类似预约。
ORDER 创建帖子,提示用户进行订购。
SHOP 创建帖子,提示用户浏览商品清单。
LEARN_MORE 创建帖子,提示用户查看网站上的其他详细信息。
SIGN_UP 创建帖子,提示用户注册、报名或参加某活动。
CALL 创建帖子,提示用户致电商家。

包含优惠信息的帖子

如需创建包含优惠信息的帖子,请使用以下代码:

HTTP
$ POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts
{
  "languageCode": "en-US",
  "summary": "Buy one Google jetpack, get a second one free!!",
  "offer": {
       "couponCode": “BOGO-JET-CODE”,
       "redeemOnlineUrl": “https://www.google.com/redeem”,
       "termsConditions": “Offer only valid if you can prove you are a time traveler”
  },
  "media": [
    {
      "mediaFormat": "PHOTO",
      "sourceUrl": "https://www.google.com/real-jetpack-photo.jpg",
    }
  ],
  "topicType": "OFFER"
}

修改帖子

创建帖子后,您可以使用 PATCH 请求对其进行修改。

如需修改某个帖子,请使用以下代码:

HTTP
$ PATCH
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts/{localPostId}?updateMask=summary
{
  "summary": "Order your Christmas turkeys now!!"
}

删除帖子

创建帖子后,您可以使用 DELETE 请求将其删除。

如需删除某个帖子,请使用以下代码:

HTTP
$ DELETE
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts/{localPostId}