您可以通过以下两种方法使用 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 通过字节上传媒体内容,请完成以下步骤:
若要开始上传,请进行以下调用:
POST https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/media:startUpload
该 API 的响应会返回一个包含
MediaItemDataRef
的正文:{ "resourceName": "GoogleProvidedValue", }
若要上传字节,请使用上一步中的调用所返回的
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"
使用第 1 步中返回的
resourceName
来调用Media.Create
。使用相关的 mediaFormat 和 category。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" }, }