全部产品
云市场
云游戏

Go SDK

更新时间:2020-04-24 19:21:49

准备工作

  1. 在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问密钥(AccessKey)。详情请参考创建AccessKey

  2. 安装Go SDK。阿里云Go SDK支持Go 1.7及以上版本,您可以通过以下方式安装Go SDK:

    使用Govendor安装。

    执行以下命令,安装阿里云Go SDK:

    1. go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk

注意:模板中yourContent 参考 模板附录

完整代码示例

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/multimediaai"
  5. )
  6. func main() {
  7. // 创建client实例
  8. client, err := multimediaai.NewClientWithAccessKey(
  9. "<region>", // 地域ID 目前支持cn-beijing
  10. "<your-access-key-id>", // RAM账号的AccessKey ID
  11. "<your-access-key-secret>") // RAM账号Access Key Secret
  12. if err != nil {
  13. // 异常处理
  14. panic(err)
  15. }
  16. // 创建结构化任务
  17. request := multimediaai.CreateCreateLabelTaskRequest()
  18. request.VideoUrl = "<yourVideoUrl>"
  19. request.VideoName = "<yourVideoName>"
  20. request.ApplicationId = "<yourApplicationId>"
  21. // request.CallbackUrl = "<yourCallbackUrl>"
  22. // request.TemplateId = "<yourTemplateId>"
  23. response, err := client.CreateLabelTask(request)
  24. if err != nil {
  25. panic(err)
  26. }
  27. fmt.Println(response)
  28. // 创建视频首图任务
  29. request := multimediaai.CreateCreateCoverTaskRequest()
  30. request.VideoUrl = "<yourVideoUrl>"
  31. request.VideoName = "<yourVideoName>"
  32. request.ApplicationId = "<yourApplicationId>"
  33. // request.CallbackUrl = "<yourCallbackUrl>"
  34. // request.TemplateId = "<yourTemplateId>"
  35. response, err := client.CreateCoverTask(request)
  36. if err != nil {
  37. panic(err)
  38. }
  39. fmt.Println(response)
  40. // 创建视频GIF任务
  41. request := multimediaai.CreateCreateGifTaskRequest()
  42. request.VideoUrl = "<yourVideoUrl>"
  43. request.VideoName = "<yourVideoName>"
  44. request.ApplicationId = "<yourApplicationId>"
  45. // request.CallbackUrl = "<yourCallbackUrl>"
  46. // request.TemplateId = "<yourTemplateId>"
  47. response, err := client.CreateGifTask(request)
  48. if err != nil {
  49. panic(err)
  50. }
  51. fmt.Println(response)
  52. // 获取任务处理状态
  53. request := multimediaai.CreateGetTaskStatusRequest()
  54. request.TaskId = <yourTaskId>
  55. response, err := client.GetTaskStatus(request)
  56. if err != nil {
  57. panic(err)
  58. }
  59. fmt.Println(response)
  60. // 获取任务处理结果
  61. request := multimediaai.CreateGetTaskResultRequest()
  62. request.TaskId = <yourTaskId>
  63. response, err := client.GetTaskResult(request)
  64. if err != nil {
  65. panic(err)
  66. }
  67. fmt.Println(response)
  68. // 创建人脸库
  69. request := multimediaai.CreateCreateFaceGroupRequest()
  70. request.FaceGroupName = <yourFaceGroupName>
  71. response, err := client.GetCreateFaceGroup(request)
  72. if err != nil {
  73. panic(err)
  74. }
  75. fmt.Println(response)
  76. // 创建人脸库人物
  77. request := multimediaai.CreateCreateFacePersonRequest()
  78. request.FaceGroupId = <yourFaceGroupId>
  79. request.FacePersonName = <yourFacePersonName>
  80. response, err := client.GetCreateFacePerson(request)
  81. if err != nil {
  82. panic(err)
  83. }
  84. fmt.Println(response)
  85. // 注册人脸
  86. request := multimediaai.CreateRegisterFaceImageRequest()
  87. request.FaceGroupId = <yourFaceGroupId>
  88. request.FacePersonId = <yourFacePersonId>
  89. request.ImageUrl = <yourImageUrl>
  90. response, err := client.GetRegisterFaceImage(request)
  91. if err != nil {
  92. panic(err)
  93. }
  94. fmt.Println(response)
  95. // 删除人脸库
  96. request := multimediaai.CreateDeleteFaceGroupRequest()
  97. request.FaceGroupId = <yourFaceGroupId>
  98. response, err := client.GetDeleteFaceGroup(request)
  99. if err != nil {
  100. panic(err)
  101. }
  102. fmt.Println(response)
  103. // 删除人脸库人物
  104. request := multimediaai.CreateDeleteFacePersonRequest()
  105. request.FaceGroupId = <yourFaceGroupId>
  106. request.FacePersonId = <yourFacePersonId>
  107. response, err := client.GetDeleteFacePerson(request)
  108. if err != nil {
  109. panic(err)
  110. }
  111. fmt.Println(response)
  112. // 删除人脸库人物图片
  113. request := multimediaai.CreateDeleteFaceImageRequest()
  114. request.FaceGroupId = <yourFaceGroupId>
  115. request.FacePersonId = <yourFacePersonId>
  116. request.FaceImageId = <yourFaceImageId>
  117. response, err := client.GetDeleteFaceImage(request)
  118. if err != nil {
  119. panic(err)
  120. }
  121. fmt.Println(response)
  122. // 获取人脸库列表
  123. request := multimediaai.CreateListFaceGroupsRequest()
  124. request.PageNumber = <yourPageNumber>
  125. request.PageSize = <yourPageSize>
  126. response, err := client.GetListFaceGroups(request)
  127. if err != nil {
  128. panic(err)
  129. }
  130. fmt.Println(response)
  131. // 获取人脸库人物列表
  132. request := multimediaai.CreateListFacePersonsRequest()
  133. request.FaceGroupId = <yourFaceGroupId>
  134. request.PageNumber = <yourPageNumber>
  135. request.PageSize = <yourPageSize>
  136. response, err := client.GetListFacePersons(request)
  137. if err != nil {
  138. panic(err)
  139. }
  140. fmt.Println(response)
  141. // 获取人脸库人物图片列表
  142. request := multimediaai.CreateListFaceImagesRequest()
  143. request.FaceGroupId = <yourFaceGroupId>
  144. request.FacePersonId = <yourFacePersonId>
  145. request.PageNumber = <yourPageNumber>
  146. request.PageSize = <yourPageSize>
  147. response, err := client.GetListFaceImages(request)
  148. if err != nil {
  149. panic(err)
  150. }
  151. fmt.Println(response)
  152. // 创建视频内容分析模板
  153. request := multimediaai.CreateCreateTemplateRequest()
  154. request.TemplateName = <yourTemplateName >
  155. request.TemplateContent = <yourContent >
  156. request.IsDefault = false
  157. request.Type = 1
  158. response, err := client.CreateTemplate(request)
  159. if err != nil {
  160. panic(err)
  161. }
  162. fmt.Println(response)
  163. // 修改视频内容分析模板
  164. request := multimediaai.CreateUpdateTemplateRequest()
  165. request.TemplateName = <yourTemplateName >
  166. request.TemplateId = <yourTemplateId >
  167. request.TemplateContent = <yourContent >
  168. request.IsDefault = false
  169. request.Type = 1
  170. response, err := client.UpdateTemplate(request)
  171. if err != nil {
  172. panic(err)
  173. }
  174. fmt.Println(response)
  175. // 查询视频内容分析模板列表
  176. request := multimediaai.CreateListTemplatesRequest()
  177. request.TemplateName = <yourTemplateName >
  178. request.TemplateId = <yourTemplateId >
  179. request.Type = <yourType>
  180. request.PageNumber = <yourPageNumber>
  181. request.PageSize = <yourPageSize>
  182. response, err := client.ListTemplates(request)
  183. if err != nil {
  184. panic(err)
  185. }
  186. fmt.Println(response)
  187. // 查询视频内容分析模板详情
  188. request := multimediaai.CreateGetTemplateRequest()
  189. request.TemplateId = <yourTemplateId >
  190. response, err := client.GetTemplate(request)
  191. if err != nil {
  192. panic(err)
  193. }
  194. fmt.Println(response)
  195. }