全部产品

.Net SDK

本文介绍淘宝联盟服务.Net SDK的使用方法及示例。

接口列表

接口名称

接口说明

SearchByPic

用于向淘宝联盟版在线调用,根据图片查询。

SearchByUrl

用户向淘宝联盟版在线调用,根据图片Url查询

准备工作

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

  1. 在解决方案资源管理器面板中,右键单击您的项目,选择管理NuGet程序包菜单。

  2. 在打开的NuGet管理面板中单击浏览选项卡输入AlibabaCloud.SDK.ImageSearch20210501 。

  3. 点击安装。

SearchByPic接口

  • 代码示例

using AlibabaCloud.OpenApiClient.Models;
using AlibabaCloud.SDK.ImageSearch20210501.Models;
using AlibabaCloud.SDK.ImageSearch20210501;
using System;
using System.IO;
using AlibabaCloud.TeaUtil.Models;

namespace netdemoimagesearch_20210501
{
    class Program
    {
        private static String PIC_NAME = "C:\\xxxxx/9.jpg";

        private static String PIC_URL = "https://ossname.oss-cn-shanghai.aliyuncs.com/m.jpg";
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            searchPic();
        }

        public static Client getClient()
        {
            Config config = new Config();
            config.AccessKeyId = "xxxxx";
            config.AccessKeySecret = "xxxxxxx";
            config.Endpoint = "imagesearch.cn-shanghai.aliyuncs.com";
            config.RegionId = "cn-shanghai";
            Client client = new Client(config);
            return client;
        }

        public static void searchPic()
        {

            SearchByPicAdvanceRequest request = new SearchByPicAdvanceRequest();
            FileStream fs = File.OpenRead(PIC_NAME);
            request.PicContentObject = fs;
            // 需要返回的字段list。不同的字段用逗号分割。默认ClickUrl,ItemName,Pic,Price,PromotionPrice字段必返回
            //request.Fields = "Provcity,UserType,CouponTotalCount,ItemId";
            // 图片类目
            //request.categoryId = 88888888;
            // 是否需要进行主体识别。默认true
            //request.crop = false;
            // 图片的主体区域,格式为x1,x2,y1,y2
            //request.region = "518,1524,398,1632";
            // 选填,返回结果的起始位置。取值范围:0-499。默认值:0。
            request.Start = 0;
            // 选填,返回结果的数目。取值范围:1-20。默认值:10。
            request.Num = 1;
            // 渠道ID。用于淘宝联盟中的渠道区分。
            //request.relationId = 1145;
            RuntimeOptions runtimeObject = new RuntimeOptions();
            SearchByPicResponse response = getClient().SearchByPicAdvance(request,runtimeObject);

            Console.WriteLine("searchPic
 " + response);

        }
    }
}

  • 结果示例

searchPic
{
  "Auctions": [
    {
      "Result": {
        "ItemId": null,
        "ItemName": "PPR三通接头配件",
        "Pic": "//img.alicdn.com/i1/xxxxx.jpg",
        "Price": "0.12",
        "PromotionPrice": "0.12",
        "PriceAfterCoupon": null,
        "UserType": null,
        "Provcity": null,
        "SellerNickName": null,
        "SellerId": null,
        "MonthSellCount": null,
        "LevelOneCategoryName": null,
        "CategoryName": null,
        "CouponActivityId": null,
        "CouponTotalCount": null,
        "CouponSendCount": null,
        "CouponRemainCount": null,
        "CouponStartTime": null,
        "CouponEndTime": null,
        "CouponStartFee": null,
        "CouponAmount": null,
        "CouponSaleTextInfo": null,
        "CalTkRate": null,
        "CouponShareUrl": null,
        "ClickUrl": "//s.click.taobao.com/tyyyyy",
        "ShortUrl": null
      },
      "RankScore": 0.8301
    }
  ]
}

SearchByUrl接口

  • 代码示例

using AlibabaCloud.OpenApiClient.Models;
using AlibabaCloud.SDK.ImageSearch20210501.Models;
using AlibabaCloud.SDK.ImageSearch20210501;
using System;
using System.IO;
using AlibabaCloud.TeaUtil.Models;

namespace netdemoimagesearch_20210501
{
    class Program
    {
        private static String PIC_NAME = "C:\\xxxl/9.jpg";

        private static String PIC_URL = "https://ossname.oss-cn-shanghai.aliyuncs.com/m.jpg";
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            searchUrl();
        }

        public static Client getClient()
        {
            Config config = new Config();
            config.AccessKeyId = "xxxx";
            config.AccessKeySecret = "xxxxxx";
            config.Endpoint = "imagesearch.cn-shanghai.aliyuncs.com";
            config.RegionId = "cn-shanghai";
            Client client = new Client(config);
            return client;
        }

        public static void searchUrl()
        {

            SearchByUrlRequest request = new SearchByUrlRequest();
            request.PicUrl = PIC_URL;
            // 需要返回的字段list。不同的字段用逗号分割。默认ClickUrl,ItemName,Pic,Price,PromotionPrice字段必返回
            //request.Fields = "Provcity,UserType,CouponTotalCount,ItemId";
            // 图片类目
            //request.categoryId = 88888888;
            // 是否需要进行主体识别。默认true
            //request.crop = false;
            // 图片的主体区域,格式为x1,x2,y1,y2
            //request.region = "518,1524,398,1632";
            // 选填,返回结果的起始位置。取值范围:0-499。默认值:0。
            request.Start = 0;
            // 选填,返回结果的数目。取值范围:1-20。默认值:10。
            request.Num = 1;
            // 渠道ID。用于淘宝联盟中的渠道区分。
            //request.relationId = 1145;
            RuntimeOptions runtimeObject = new RuntimeOptions();
            SearchByUrlResponse response = getClient().SearchByUrl(request);

            Console.WriteLine("searchUrl
 " + Newtonsoft.Json.JsonConvert.SerializeObject(response.Body.Data));

        }
    }
}

  • 结果示例

searchUrl
{
  "Auctions": [
    {
      "Result": {
        "ItemId": null,
        "ItemName": "PPR三通接头配件",
        "Pic": "//img.alicdn.com/i1/xxxxx.jpg",
        "Price": "0.12",
        "PromotionPrice": "0.12",
        "PriceAfterCoupon": null,
        "UserType": null,
        "Provcity": null,
        "SellerNickName": null,
        "SellerId": null,
        "MonthSellCount": null,
        "LevelOneCategoryName": null,
        "CategoryName": null,
        "CouponActivityId": null,
        "CouponTotalCount": null,
        "CouponSendCount": null,
        "CouponRemainCount": null,
        "CouponStartTime": null,
        "CouponEndTime": null,
        "CouponStartFee": null,
        "CouponAmount": null,
        "CouponSaleTextInfo": null,
        "CalTkRate": null,
        "CouponShareUrl": null,
        "ClickUrl": "//s.click.taobao.com/tyyyyy",
        "ShortUrl": null
      },
      "RankScore": 0.8301
    }
  ]
}