全部产品

截图模板

本篇文档提供了Go SDK截图模板功能的API调用示例。包含添加截图模板、修改截图模板、删除截图模板、查询截图模板列表。

初始化客户端

使用前请先初始化客户端,请参见初始化

添加截图模板

调用AddVodTemplate接口,完成添加截图模板功能。

接口参数和返回字段请参见AddVodTemplate。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyAddVodTemplate(client *vod.Client) (response *vod.AddVodTemplateResponse, err error) {
    request := vod.CreateAddVodTemplateRequest()

    // 模板名称
    request.Name = "Sample Snapshot Template"
    // 模板类型,固定值为Snapshot
    request.TemplateType = "Snapshot"

    // 截图模板配置数据
    snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
        "Height": 200, "FrameType": "normal"}
    templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}

    /*
    // 可选项:雪碧图配置(雪碧图配置必须建立在普通截图配置之上)
    spriteSnapshotConfig := map[string]interface{}{"CellWidth": 120, "CellHeight": 68, "Columns": 3, "Lines": 10,
        "Padding": 20, "Margin": 50, "KeepCellPic": "keep", "Color": "tomato"}
    snapshotConfig["SpriteSnapshotConfig"] = spriteSnapshotConfig
    templateConfig["SnapshotType"] = "SpriteSnapshot"
    */

    jsonConfig, err := json.Marshal(templateConfig)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TemplateConfig = string(jsonConfig)

    request.AcceptFormat = "JSON"

    return client.AddVodTemplate(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyAddVodTemplate(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.VodTemplateId)
}

修改截图模板

调用UpdateVodTemplate接口,完成修改截图模板功能。

接口参数和返回字段请参见UpdateVodTemplate。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyUpdateVodTemplate(client *vod.Client) (response *vod.UpdateVodTemplateResponse, err error) {
    request := vod.CreateUpdateVodTemplateRequest()

    request.VodTemplateId = "c0825c5f4c4a43af56abf9826b2d****"
    // 模板名称
    request.Name = "New Snapshot Template Name"

    // 修改截图模板配置
    snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
        "Height": 200, "FrameType": "normal"}
    templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}

    jsonConfig, err := json.Marshal(templateConfig)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TemplateConfig = string(jsonConfig)

    request.AcceptFormat = "JSON"

    return client.UpdateVodTemplate(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyUpdateVodTemplate(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

删除截图模板

调用DeleteVodTemplate接口,完成删除截图模板功能。

接口参数和返回字段请参见DeleteVodTemplate。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyDeleteVodTemplate(client *vod.Client) (response *vod.DeleteVodTemplateResponse, err error) {
    request := vod.CreateDeleteVodTemplateRequest()
    request.VodTemplateId = "<TemplateId>"

    request.AcceptFormat = "JSON"

    return client.DeleteVodTemplate(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteVodTemplate(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

查询截图模板列表

调用ListVodTemplate接口,完成查询截图模板列表功能。

接口参数和返回字段请参见ListVodTemplate。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyListVodTemplate(client *vod.Client) (response *vod.ListVodTemplateResponse, err error) {
    request := vod.CreateListVodTemplateRequest()
    // 模板类型,固定值为Snapshot
    request.TemplateType = "Snapshot"

    request.AcceptFormat = "JSON"

    return client.ListVodTemplate(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyListVodTemplate(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    for _, template := range response.VodTemplateInfoList {
        fmt.Printf("%s: %s %s\n", template.VodTemplateId, template.Name, template.TemplateConfig)
    }
}

查询截图模板

调用GetVodTemplate接口,完成查询截图模板功能。

接口参数和返回字段请参见GetVodTemplate。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyGetVodTemplate(client *vod.Client) (response *vod.GetVodTemplateResponse, err error) {
    request := vod.CreateGetVodTemplateRequest()
    request.VodTemplateId = "<TemplateId>"

    request.AcceptFormat = "JSON"

    return client.GetVodTemplate(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetVodTemplate(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Printf("%s: %s\n", response.VodTemplateInfo.Name, response.VodTemplateInfo.TemplateConfig)
}