Services的itemsearch提供C#示例

Services的itemsearch提供C#示例

本文介绍了有人可以使用Amazon Web Services的itemsearch提供C#示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Amazon Web Services查询艺术家和标题信息并接收专辑封面。使用C#,我找不到与之接近的任何示例。在线上的所有示例均已过时,不能与AWS的较新版本一起使用。

I am trying to use Amazon Web Services to query Artist and title information and receive album art back. Using C# I cannot find any examples that come even close to this. All of the examples online are outdated and do not work with AWS' newer version.

推荐答案

在这里,您物有所值。这是Asp.Net控件中用于显示书籍信息的代码。您可以很容易地将其适应您的目的。或至少给您一个起点。如果您确实需要,我很乐意将控件捆绑在一起并发送给您。

Here you go for what it's worth. This is code within an Asp.Net control to display book information. You can probably adapt it for your purposes easily enough. Or at least give you a starting-point. If you really want, I'd be happy to bundle the control up and send it your way.

if (!(string.IsNullOrEmpty(ISBN) && string.IsNullOrEmpty(ASIN)))
{
    AWSECommerceService service = new AWSECommerceService();
    ItemLookup lookup = new ItemLookup();
    ItemLookupRequest request = new ItemLookupRequest();

    lookup.AssociateTag = ConfigurationManager.AppSettings["AssociatesTag"];
    lookup.AWSAccessKeyId = ConfigurationManager.AppSettings["AWSAccessKey"];
    if (string.IsNullOrEmpty(ASIN))
    {
        request.IdType = ItemLookupRequestIdType.ISBN;
        request.ItemId = new string[] { ISBN.Replace("-", "") };
    }
    else
    {
        request.IdType = ItemLookupRequestIdType.ASIN;
        request.ItemId = new string[] { ASIN };
    }
    request.ResponseGroup = ConfigurationManager.AppSettings["AWSResponseGroups"].Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

    lookup.Request = new ItemLookupRequest[] { request };
    ItemLookupResponse response = service.ItemLookup(lookup);

    if (response.Items.Length > 0 && response.Items[0].Item.Length > 0)
    {
        Item item = response.Items[0].Item[0];
        if (item.MediumImage == null)
        {
            bookImageHyperlink.Visible = false;
        }
        else
        {
            bookImageHyperlink.ImageUrl = item.MediumImage.URL;
        }
        bookImageHyperlink.NavigateUrl = item.DetailPageURL;
        bookTitleHyperlink.Text = item.ItemAttributes.Title;
        bookTitleHyperlink.NavigateUrl = item.DetailPageURL;
        if (item.OfferSummary.LowestNewPrice == null)
        {
            if (item.OfferSummary.LowestUsedPrice == null)
            {
                priceHyperlink.Visible = false;
            }
            else
            {
                priceHyperlink.Text = string.Format("Buy used {0}", item.OfferSummary.LowestUsedPrice.FormattedPrice);
                priceHyperlink.NavigateUrl = item.DetailPageURL;
            }
        }
        else
        {
            priceHyperlink.Text = string.Format("Buy new {0}", item.OfferSummary.LowestNewPrice.FormattedPrice);
            priceHyperlink.NavigateUrl = item.DetailPageURL;
        }
        if (item.ItemAttributes.Author != null)
        {
            authorLabel.Text = string.Format("By {0}", string.Join(", ", item.ItemAttributes.Author));
        }
        else
        {
            authorLabel.Text = string.Format("By {0}", string.Join(", ", item.ItemAttributes.Creator.Select(c => c.Value).ToArray()));
        }
        ItemLink link = item.ItemLinks.Where(i => i.Description.Contains("Wishlist")).FirstOrDefault();
        if (link == null)
        {
            wishListHyperlink.Visible = false;
        }
        else
        {
            wishListHyperlink.NavigateUrl = link.URL;
        }
    }
}

这篇关于有人可以使用Amazon Web Services的itemsearch提供C#示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:07