淘宝API 添加上传商品图片

来源:互联网 发布:淘宝农村合伙人报名 编辑:程序博客网 时间:2024/04/27 22:46

 /// <summary>
    /// 添加商品图片
    /// </summary>
    public void getShopImage() {
        string fileName = Server.MapPath("tp" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + DateTime.Now.Millisecond + ".jpg");
        fuImage.SaveAs(fileName);
        string strXml = string.Empty;
        Dictionary<string, string> param = new Dictionary<string, string>();
        param.Add("id","003");//图片id
        param.Add("num_iid", "7962992576");//商品id
        param.Add("properties", "2");
        Dictionary<string, FileItem> param3 = new Dictionary<string, FileItem>();
        param3.Add("image", new FileItem(new System.IO.FileInfo(fileName)));
        strXml = TopAPI.Post("taobao.item.img.upload", Client.Session, param, param3);
         Parser parse3 = new Parser();
        PropImgResponse img = new PropImgResponse();//返回结果
        ErrorRsp shoperr = new ErrorRsp();//错误消息对象
        parse3.XmlToObject2(strXml, "item_img_upload", "item_img/url", img, shoperr);
        if (shoperr.IsError == true)
        {
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "error", string.Format("alert(\"添加图片发生错误!\\r错误代码:{0}\\r错误原因:{1}\\r错误描述:{2}-{3}\");", shoperr.code, shoperr.msg, shoperr.sub_code, shoperr.sub_msg), true);
        }
    }

 

以上代码是传不上去的,缺少app_key   session   是否传的正确
添加即可。