全部产品
云市场

截图模板

更新时间:2019-01-02 15:51:18

初始化客户端

使用前请先初始化客户端,参考 InitVodClient 接口。

添加截图模板

接口参数和返回字段请参考 AddVodTemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyAddVodTemplate(client *vod.Client) (response *vod.AddVodTemplateResponse, err error) {
  10. request := vod.CreateAddVodTemplateRequest()
  11. // 模板名称
  12. request.Name = "Sample Snapshot Template"
  13. // 模板类型,固定值为Snapshot
  14. request.TemplateType = "Snapshot"
  15. // 截图模板配置数据
  16. snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
  17. "Height": 200, "FrameType": "normal"}
  18. templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}
  19. /*
  20. // 可选项:雪碧图配置(雪碧图配置必须建立在普通截图配置之上)
  21. spriteSnapshotConfig := map[string]interface{}{"CellWidth": 120, "CellHeight": 68, "Columns": 3, "Lines": 10,
  22. "Padding": 20, "Margin": 50, "KeepCellPic": "keep", "Color": "tomato"}
  23. snapshotConfig["SpriteSnapshotConfig"] = spriteSnapshotConfig
  24. templateConfig["SnapshotType"] = "SpriteSnapshot"
  25. */
  26. jsonConfig, err := json.Marshal(templateConfig)
  27. if err != nil {
  28. fmt.Println("json.Marshal failed:", err)
  29. return
  30. }
  31. request.TemplateConfig = string(jsonConfig)
  32. request.AcceptFormat = "JSON"
  33. return client.AddVodTemplate(request)
  34. }
  35. func main() {
  36. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  37. if err != nil {
  38. panic(err)
  39. }
  40. response, err := MyAddVodTemplate(client)
  41. if err != nil {
  42. panic(err)
  43. }
  44. fmt.Println(response.GetHttpContentString())
  45. fmt.Println(response.RequestId)
  46. fmt.Println(response.VodTemplateId)
  47. }

修改截图模板

接口参数和返回字段请参考 UpdateVodTemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyUpdateVodTemplate(client *vod.Client) (response *vod.UpdateVodTemplateResponse, err error) {
  10. request := vod.CreateUpdateVodTemplateRequest()
  11. request.VodTemplateId = "c0825c5f4c4a43af56abf9826b2d4e4f"
  12. // 模板名称
  13. request.Name = "New Snapshot Template Name"
  14. // 修改截图模板配置
  15. snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
  16. "Height": 200, "FrameType": "normal"}
  17. templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}
  18. jsonConfig, err := json.Marshal(templateConfig)
  19. if err != nil {
  20. fmt.Println("json.Marshal failed:", err)
  21. return
  22. }
  23. request.TemplateConfig = string(jsonConfig)
  24. request.AcceptFormat = "JSON"
  25. return client.UpdateVodTemplate(request)
  26. }
  27. func main() {
  28. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  29. if err != nil {
  30. panic(err)
  31. }
  32. response, err := MyUpdateVodTemplate(client)
  33. if err != nil {
  34. panic(err)
  35. }
  36. fmt.Println(response.GetHttpContentString())
  37. fmt.Println(response.RequestId)
  38. }

删除截图模板

接口参数和返回字段请参考 DeleteVodTemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyDeleteVodTemplate(client *vod.Client) (response *vod.DeleteVodTemplateResponse, err error) {
  10. request := vod.CreateDeleteVodTemplateRequest()
  11. request.VodTemplateId = "<TemplateId>"
  12. request.AcceptFormat = "JSON"
  13. return client.DeleteVodTemplate(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyDeleteVodTemplate(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. }

查询截图模板列表

接口参数和返回字段请参考 ListVodTemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyListVodTemplate(client *vod.Client) (response *vod.ListVodTemplateResponse, err error) {
  10. request := vod.CreateListVodTemplateRequest()
  11. // 模板类型,固定值为Snapshot
  12. request.TemplateType = "Snapshot"
  13. request.AcceptFormat = "JSON"
  14. return client.ListVodTemplate(request)
  15. }
  16. func main() {
  17. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  18. if err != nil {
  19. panic(err)
  20. }
  21. response, err := MyListVodTemplate(client)
  22. if err != nil {
  23. panic(err)
  24. }
  25. fmt.Println(response.GetHttpContentString())
  26. fmt.Println(response.RequestId)
  27. for _, template := range response.VodTemplateInfoList {
  28. fmt.Printf("%s: %s %s\n", template.VodTemplateId, template.Name, template.TemplateConfig)
  29. }
  30. }

查询截图模板

接口参数和返回字段请参考 GetVodTemplate

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyGetVodTemplate(client *vod.Client) (response *vod.GetVodTemplateResponse, err error) {
  10. request := vod.CreateGetVodTemplateRequest()
  11. request.VodTemplateId = "<TemplateId>"
  12. request.AcceptFormat = "JSON"
  13. return client.GetVodTemplate(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyGetVodTemplate(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. fmt.Printf("%s: %s\n", response.VodTemplateInfo.Name, response.VodTemplateInfo.TemplateConfig)
  27. }