上傳媒體內容

您可以透過下列兩種方式使用 Google My Business API 上傳媒體:

透過網址上傳

如要從網址上傳相片,請將下列呼叫傳送至 Media.Create。使用符合需求的 category [類別] 將物件的使用中版本還原為舊版 或依需要永久刪除封存版本

POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media
{
  "mediaFormat": "PHOTO",
  "locationAssociation": {
    "category": "COVER"
  },
  "sourceUrl": “http://example.com/biz/image.jpg",
}

如要使用 Google My Business API 從網址上傳影片,請呼叫下列呼叫: Media.Create:

POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media
{
  "mediaFormat": "VIDEO",
  "locationAssociation": {
    "category": "ADDITIONAL"
  },
  "sourceUrl": “http://example.com/biz/video.mp4",
}

從位元組上傳

如要使用 Google My Business API 從位元組上傳媒體,請完成下列步驟:

  1. 如要開始上傳,請發出下列呼叫:

      POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media:startUpload
      

    API 的回應會傳回主體包含 MediaItemDataRef

      {
      "resourceName": "GoogleProvidedValue",
      }
  2. 如要上傳位元組,請使用resourceName 上一個步驟以下範例為要上傳的媒體是相片:

    curl -X POST -T ~/Downloads/pictureToUpload.jpg  "https://mybusiness.googleapis.com/upload/v1/media/{GoogleProvidedValue}?upload_type=media"

    以下範例為影片的影片:

    curl -X POST -T ~/Downloads/videoToUpload.mp4  "https://mybusiness.googleapis.com/upload/v1/media/{GoogleProvidedValue}?upload_type=media"
  3. 使用步驟 1 中傳回的 resourceName 呼叫 Media.Create。 使用符合需求的 mediaFormatcategory

      POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media
      {
        "mediaFormat": "PHOTO",
        "locationAssociation": {
          "category": "COVER"
        },
        "dataRef": {
          "resourceName": "GoogleProvidedValue"
        },
      }
      POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media
      {
        "mediaFormat": "VIDEO",
        "locationAssociation": {
          "category": "ADDITIONAL"
        },
        "dataRef": {
          "resourceName": "GoogleProvidedValue"
        },
      }