全部产品

媒资分类

本篇文档提供了Go SDK媒资分类模块相关功能的的API调用示例,包含创建分类、删除分类、修改分类、查寻分类及其子分类。

初始化客户端

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

创建分类

调用AddCategory接口,完成创建分类功能。

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

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"
    "fmt"
)

func MyAddCategory(client *vod.Client) (response *vod.AddCategoryResponse, err error) {
    request := vod.CreateAddCategoryRequest()
    request.CateName = "sample category name"
    request.ParentId = "-1"
    request.AcceptFormat = "JSON"

    return client.AddCategory(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.Category.CateId)
}

修改分类

调用UpdateCategory接口,完成修改分类功能。

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

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"
    "fmt"
)

func MyUpdateCategory(client *vod.Client) (response *vod.UpdateCategoryResponse, err error) {
    request := vod.CreateUpdateCategoryRequest()
    request.CateId = "<CateId>"
    request.CateName = "sample category name"
    request.AcceptFormat = "JSON"

    return client.UpdateCategory(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
}

删除分类

调用DeleteCategory接口,完成删除分类功能。

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

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"
    "fmt"
)

func MyDeleteCategory(client *vod.Client) (response *vod.DeleteCategoryResponse, err error) {
    request := vod.CreateDeleteCategoryRequest()
    request.CateId = "<CateId>"
    request.AcceptFormat = "JSON"

    return client.DeleteCategory(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
}

查询分类及其子分类

调用GetCategories接口,完成查询分类及其子分类功能。

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

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"
    "fmt"
)

func MyGetCategories(client *vod.Client) (response *vod.GetCategoriesResponse, err error) {
    request := vod.CreateGetCategoriesRequest()
    request.CateId = "<CateId>"
    request.PageNo = "1"
    request.PageSize = "20"
    request.AcceptFormat = "JSON"

    return client.GetCategories(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
}