对象标签使用一组键值对(Key-Value)来标记对象。本文介绍如何获取对象标签。

以下代码用于获取对象标签:

using Aliyun.OSS;
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var objectName = "<yourObjectName>";
// 创建OssClient实例。
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
    // 获取对象标签信息。
    var result = client.GetObjectTagging(bucketName,objectName);
    Console.WriteLine("get objects tagging succeeded");
    foreach (var tag in result.Tags)
    {
        Console.WriteLine("key:{0}, value:{1}", tag.Key, tag.Value);
    }
}
catch (Exception ex)
{
    Console.WriteLine("get objects tagging failed. {0}", ex.Message);
}

有关获取对象标签的详情请参见GetObjectTagging。有关对象标签的详情请参见对象标签