This topic describes the sample code that is used to call an API operation by using the server SDK to refresh the credential for uploading a media asset.
Sample code
You can use Alibaba Cloud OpenAPI Explorer to perform online debugging.
package main
import (
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
ice "github.com/alibabacloud-go/ice-20201109/v2/client"
"github.com/aliyun/credentials-go/credentials"
"github.com/alibabacloud-go/tea/tea"
)
func main() {
// An AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M.
// In this example, the AccessKey ID and the AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-go-access-credentials?spm=a2c63.p38356.help-menu-262060.d_1_9_1_2.16c2662axiCNKz.
credential, _err := credentials.NewCredential(nil)
if _err != nil {
panic(_err)
}
iceClient, _err := ice.NewClient(&openapi.Config{
Credential: credential,
Endpoint: tea.String("ice.cn-shanghai.aliyuncs.com"),
})
// To hard-code your AccessKey ID and AccessKey secret, use the following code. We recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised.
// config := new(openapi.Config)
// config.SetAccessKeyId("<accessKeyId>").
// SetAccessKeySecret("<accessKeySecret>").
// SetRegionId("<regionId>").
// SetEndpoint("<endpoint>")
// iceClient, _err := ice.NewClient(config)
if _err != nil {
panic(_err)
}
// Refresh the credential for uploading a media asset.
mediaId := "09c6aa40491c71ed9520472190a9xxxx"
request := &ice.RefreshUploadMediaRequest{
MediaId: &mediaId,
}
response, err := iceClient.RefreshUploadMedia(request)
fmt.Println(response, err)
}