0

Hi guys I'm having trouble fetching products from amazon web api.

I have used this code from the internet, adding all the neccessary references. I tried adding a view and chose itemsearchresponce as the model class but it does not display the product, I get the following error:

Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'AmazonProduct.com.amazon.webservices.ImageSet' to 'AmazonProduct.com.amazon.webservices.ImageSet[]'

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using AmazonProduct.com.amazon.webservices;
namespace Forest.Controllers
{
    public class AmazonController : Controller
    {
        private AmazonProduct.com.amazon.webservices.AWSECommerceService _Products;

        public AmazonController()
        {
            _Products = new AmazonProduct.com.amazon.webservices.AWSECommerceService();
        }

        [HttpGet]
        public ActionResult  listProducts()
        {
            var searchIndex = "Shoes";
            var keywords = "jordan";
            // Create an ItemSearch wrapper
            ItemSearch search = new ItemSearch();
            search.AssociateTag = "[Your Associate ID]";
            search.AWSAccessKeyId = "MyKey";
            // search.Version= "2011-08-01";

            // Create a request object
            ItemSearchRequest request = new ItemSearchRequest();

            // Fill the request object with request parameters
            request.ResponseGroup = new string[] { "ItemAttributes" };

            // Set SearchIndex and Keywords
            request.SearchIndex = searchIndex;
            request.Keywords = keywords;

            // Set the request on the search wrapper
            search.Request = new ItemSearchRequest[] { request };

            ItemSearchResponse response = _Products.ItemSearch(search);

            return View(response);
        }
    }
}
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Since you're just passing the result back with the view, the error is most likely occurring in your View where you work with the ImageSet. The error appears to state that your result is actually an ImageSet[] (array of ImageSet objects) whereas somewhere in your code - not the code you posted - you're trying to treat that result as a single ImageSet. Find that place and you'll find the problem. Or post the relevant view code for further help. – Dmitriy Khaykin Mar 31 '14 at 02:00

1 Answers1

1

Go to the generated proxy and replace ImageSet[][] with ImageSet[].
Also take a look at Amazon Product Advertising API C# if you already haven't.

Community
  • 1
  • 1
Kniganapolke
  • 5,073
  • 5
  • 22
  • 19