2011-03-17 18 views
0

私はVisual Studio 2008を使っていて、書籍のようなAPI itemsearchをやろうとしています。 私はaccessKeyIdを使用していますが、「検索」ボタンをクリックして本を検索すると、署名エラーが発生します。 secretKeyIDも使用する必要がありますか? 私はVisual Studioで新しいASP.Net Webサイトを作成しました。または、AWS SDK for.Netパッケージを使用する必要がありますか?asp.net amazon itemsearch

誰かが良いアドバイスをしてください。 ありがとう!

答えて

2

署名エラーは、要求署名を適切に作成しなかったことを意味します。 SprightlySoft AWS Component for .NETを使用する必要があります。無料で、Product Advertising APIをサポートしています。 http://sprightlysoft.com/で入手してください。 AWS SDK for.NETはProduct Advertising APIと連携しません。

次は、SprightlySoftコンポーネントでItemSearchを呼び出す例です。

//Product Advertising API, ItemSearch: http://docs.amazonwebservices.com/AWSECommerceService/2010-10-01/DG/ItemSearch.html 

SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST(); 

String RequestURL; 
RequestURL = "https://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&Version=2010-10-01"; 
RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z")); 
RequestURL += "&Actor=" + System.Uri.EscapeDataString("Tom Cruise"); 
RequestURL += "&SearchIndex=DVD"; 
RequestURL += "&ResponseGroup=" + System.Uri.EscapeDataString("ItemAttributes,Reviews"); 
RequestURL += "&Sort=salesrank"; 
RequestURL += "&ItemPage=1"; 

String RequestMethod; 
RequestMethod = "GET"; 

String SignatureValue; 
SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text); 

RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue); 

Boolean RetBool; 
RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null); 
System.Diagnostics.Debug.Print(MyREST.LogData); 

String ResponseMessage = ""; 

if (RetBool == true) 
{ 
    System.Xml.XmlDocument MyXmlDocument; 
    System.Xml.XmlNamespaceManager MyXmlNamespaceManager; 
    System.Xml.XmlNode MyXmlNode; 
    System.Xml.XmlNodeList MyXmlNodeList; 

    MyXmlDocument = new System.Xml.XmlDocument(); 
    MyXmlDocument.LoadXml(MyREST.ResponseString); 

    MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable); 
    MyXmlNamespaceManager.AddNamespace("amz", "http://webservices.amazon.com/AWSECommerceService/2010-10-01"); 

    MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ItemSearchResponse/amz:Items/amz:Item", MyXmlNamespaceManager); 

    if (MyXmlNodeList.Count == 0) 
    { 
     ResponseMessage = "No items exist."; 
    } 
    else 
    { 
     foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList) 
     { 
      MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:Title", MyXmlNamespaceManager); 
      ResponseMessage += "Title = " + MyXmlNode.InnerText; 

      MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:ListPrice/amz:FormattedPrice", MyXmlNamespaceManager); 
      ResponseMessage += " ListPrice = " + MyXmlNode.InnerText; 

      ResponseMessage += Environment.NewLine; 
     } 
    } 

    MessageBox.Show(ResponseMessage); 
} 
else 
{ 
    MessageBox.Show(MyREST.ResponseStringFormatted); 
} 
関連する問題