在 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}