注意:此 API 的 v4.7 版本已发布!请参阅更新日志。仍暂时允许在链中提供与新冠肺炎 (COVID-19) 相关的帖子。

上传媒体内容

您可以使用以下两种方法将媒体内容上传到 Google My Business API:

通过网址上传

要使用网址将照片上传到 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",
}

要使用网址上传视频,请对 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"
        },
      }