Google My Business API 可讓你在 Google 搜尋中建立多種貼文,例如新聞、活動和優惠。
本教學課程說明如何執行下列操作:
事前準備
使用 Google My Business API 前,請先註冊應用程式並取得 OAuth 2.0 憑證。
如要瞭解如何開始使用 Google My Business API,請參閱基本設定。
活動貼文
透過貼文通知顧客貴商家即將舉辦的活動。活動貼文會顯示開始和結束日期與時間,並在貼文中醒目顯示。
如要將貼文發布至與使用者相關聯的帳戶,請使用 accounts.locations.localPosts API。
如要為已驗證的使用者建立貼文,請使用下列項目:
$ 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 欄位。按鈕會新增使用者提供的網址連結。
如要建立含有行動號召按鈕的貼文,請使用下列項目:
$ 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 |
建立貼文,提示使用者撥打商家電話。 |
優惠貼文
如要建立優惠貼文,請使用下列項目:
$ 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 要求編輯貼文。
如要編輯貼文,請使用下列項目:
$ PATCH https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts/{localPostId}?updateMask=summary { "summary": "Order your Christmas turkeys now!!" }
刪除貼文
建立貼文後,您可以透過 DELETE 要求刪除貼文。
如要刪除貼文,請使用下列指令:
$ DELETE https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/localPosts/{localPostId}