Google My Business API 可讓您在 Google 搜尋中建立多個類別的貼文,例如新聞、活動和優惠。
本教學課程將說明如何執行下列操作:
事前準備
使用 Google 我的商家 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" }
行動號召貼文
含有行動號召的貼文會附上按鈕。行動號召按鈕上的文字是由 Post 的 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}