Reputation: 13
I am at the initial stage of getting my project to build with the Nuget package.
I have installed the Nuget package: https://github.com/nager/Nager.AmazonProductAdvertising
I have started up a 4.8 .NET Framework C# console application solution and it has one C# project with the following code:
using System;
using System.Threading.Tasks;
using Nager.AmazonProductAdvertising;
using Nager.AmazonProductAdvertising.Model;
namespace AmazonProductAdvertisingExample
{
class Program
{
static async Task Main(string[] args)
{
var accessKey = "yourAccessKey";
var secretKey = "yourSecretKey";
var associateTag = "yourAssociateTag";
var authentication = new AmazonAuthentication(accessKey, secretKey);
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US, associateTag);
await SearchProductsAsync(client, "programming books");
}
private static async Task SearchProductsAsync(AmazonProductAdvertisingClient client, string keywords)
{
var searchRequest = new SearchRequest
{
Keywords = keywords,
Resources = new[] {
"ItemInfo.Title",
"ItemInfo.ByLineInfo",
"Offers.Listings.Price"
}
};
var response = await client.SearchItemsAsync(searchRequest);
if (response.Success)
{
foreach (var item in response.SearchResult.Items)
{
Console.WriteLine($"{item.ASIN} - {item.ItemInfo.Title.DisplayValue}");
}
}
else
{
Console.WriteLine($"Failed to search items: {response.Error.Message}");
}
}
}
}
I have four errors and cannot compile:
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'AmazonProductAdvertisingClient' could not be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line Suppression State Error CS1729 'AmazonAuthentication' does not contain a constructor that takes 2 arguments
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'AmazonProductAdvertisingClient' could not be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'SearchRequest' could not be found (are you missing a using directive or an assembly reference?)
Upvotes: 1
Views: 237
Reputation: 13
Ok to get this to work I did the following:
I am happy it's working but have no understanding of why I had to do it this way. If anyone wants to pipe in on that.
Upvotes: 0