全部产品

.NET SDK

准备工作

  1. 在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问密钥(AccessKey)。详情请参考创建AccessKey

  2. 将 SDK添加到项目中通过 NuGet程序包管理器来安装,在解决方案资源管理器面板中右击您的项目选择管理 NuGet程序包菜单,在打开的 NuGet管理面板中点击浏览选项卡输入:

    AlibabaCloud.SDK.Videosearch20200225
    (最新版本1.1.2)

    选择并点击安装即可。

完整代码示例

usingSystem;
usingAlibabaCloud.RPCClient.Models;
usingAlibabaCloud.SDK.Videosearch20200225;
usingAlibabaCloud.SDK.Videosearch20200225.Models;
usingAlibabaCloud.TeaUtil.Models;
usingNewtonsoft.Json;
usingTea;

namespaceConsoleApplication1
{
internal classProgram
{
public static voidMain(string[]args)
{
Configconfig =newConfig();
config.AccessKeyId="<yourAccessKeyId>";
config.AccessKeySecret="<yourAccessKey>";
config.RegionId="<regionId>";
config.Endpoint="<endpoint>";
Clientclient =newClient(config);
// 创建视频入库任务 
 AddStorageVideoTask(client);

// 创建检索任务
 addSearchVideoTask(client);

// 获取任务状态
 getTaskStatus(client);

// 获取入库历史 
 getStorageHistory(client);

// 删除视频 
 addDeletionVideoTask(client);

// 查询批量任务 
 listBatchTask(client);

//查询音频实例检索任务列表  
 ListSearchAudioTask(client);

//音频实例入库 
  listStorageAudioTasks(client);

//创建批量任务
createBatchTask(client);
}



private static voidAddStorageVideoTask(Clientclient)
{
AddStorageVideoTaskRequestrequest =newAddStorageVideoTaskRequest();
// 实例id
request.InstanceId="<yourInstanceId>";
// 视频url
request.VideoUrl="<yourVideoUrl>";
// 视频id(业务key)
request.VideoId="<yourVideoId>";
// 视频描述
request.Description="<yourDescription>";
// 视频标签
request.VideoTags="<yourVideoTags>";
// 入库完成的回调
// request.CallbackUrl = "<yourCallbackUrl>";
try
{
AddStorageVideoTaskResponseresponse = client.AddStorageVideoTask(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+JsonConvert.SerializeObject(response.Data));
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

private static voidaddSearchVideoTask(Clientclient)
{
AddSearchVideoTaskRequestrequest =newAddSearchVideoTaskRequest();

// 实例id
request.InstanceId="<yourInstanceId>";
// 检索类型(1. 视频搜视频   2. 图片搜视频)
request.SearchType=1;
// 视频/图片的url地址
//如果需要使用 本地文件上传的功能,则用xxxFileObject参数并且使用 AddSearchXXXTaskAdvanceRequest对象
request.VideoUrl="<yourVideoUrl>";
// 视频/图片的描述
request.Description="<yourDescription>";
// 检索标签
// request.QueryTags = "<yourQueryTags>";
// 返回结果数
request.ReturnVideoNumber=20;
// 查询入库类型,当检索类型为1时生效(1. 直接入库  2. 去重入库  3. 不入库)
request.StorageType=3;
// 视频id,当searchType为1且storageType为1,2时生效
request.VideoId="123";
// 视频标签,当searchType为1且storageType为1,2时生效
request.VideoTags="123";
// 去重入库阈值,searchType为1且storageType为2时生效
request.ReplaceStorageThreshold=0.75F;
// 检索完成的回调
// request.CallbackUrl = "<yourCallbackUrl>";
try
{
AddSearchVideoTaskResponseresponse = client.AddSearchVideoTask(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+JsonConvert.SerializeObject(response.Data));
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}


private static voidgetTaskStatus(Clientclient)
{
GetTaskStatusRequestrequest =newGetTaskStatusRequest();
// 实例id
request.InstanceId="<yourInstanceId>";
// 任务id
request.TaskId="<yourTaskId>";
try
{
GetTaskStatusResponseresponse = client.GetTaskStatus(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response.Data);
Console.WriteLine("TaskInfo : "+JsonConvert.SerializeObject(response.TaskInfo));
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}


private static voidgetStorageHistory(Clientclient)
{
GetStorageHistoryRequestrequest =newGetStorageHistoryRequest();
// 实例id
request.InstanceId="<yourInstanceId>";
// 视频id
request.VideoId="<yourVideoId>";
// 当前页数
request.PageNumber=1;
// 分页大小
request.PageSize=10;
try
{
GetStorageHistoryResponseresponse = client.GetStorageHistory(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+JsonConvert.SerializeObject(response.Data));
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

private static voidaddDeletionVideoTask(Clientclient)
{
AddDeletionVideoTaskRequestrequest =newAddDeletionVideoTaskRequest();
// 实例id
request.InstanceId="<yourInstanceId>";
// 视频id
request.VideoId="<yourVideoId>";
try
{
AddDeletionVideoTaskResponseresponse = client.AddDeletionVideoTask(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response.Data);
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

private static voidlistBatchTask(Clientclient)
{
ListBatchTaskRequestrequest =newListBatchTaskRequest();
// 实例id
request.InstanceId="<yourInstanceId>";

try
{
ListBatchTaskResponseresponse = client.ListBatchTask(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response.Data);
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}


private static voidListSearchAudioTask(Clientclient)
{
ListSearchAudioTasksRequestrequest =newListSearchAudioTasksRequest();
// 实例id
request.InstanceId="<yourInstanceId>";

try
{
ListSearchAudioTasksResponseresponse = client.ListSearchAudioTasks(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response.Data);
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

private static voidlistStorageAudioTasks(Clientclient)
{
ListStorageAudioTasksRequestrequest =newListStorageAudioTasksRequest();
// 实例id
request.InstanceId="<yourInstanceId>";

try
{
ListStorageAudioTasksResponseresponse = client.ListStorageAudioTasks(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response.Data);
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

private static voidcreateBatchTask(Clientclient)
{
CreateBatchTaskRequestrequest =newCreateBatchTaskRequest();
// 实例id
request.InstanceId="<yourInstanceId>";
request.BatchTaskType=1;
request.RoleArn="<yourRoleArn>";
request.OssBucketName="<yourOssBucketName>";
request.OssDataPath="<yourOssDataPath>";
request.OssMetaFile="<yourOssMetaFile>";

try
{
CreateBatchTaskResponseresponse = client.CreateBatchTask(request,newRuntimeOptions());
Console.WriteLine("requestId : "+ response.RequestId);
Console.WriteLine("Data : "+ response);
}
catch(TeaUnretryableExceptione)
{
if(e.InnerException!=null)
{
Console.WriteLine("InnerException结果:"+ e.InnerException.Message);
}
Console.WriteLine("Data结果:"+ e.Data);
Console.WriteLine("Message结果:"+ e.Message);
Console.WriteLine("打印String:"+ e);
}
}

}
}