【已解决】C#中如何通过AWS去获得Merchant的Id和name,即MerchantId和商家名字

【问题】

C#,AWS

对于某个item,想要获得所有的卖家,即offers,所以知道要去用

Offers response group

但是在得到了卖家的总体个数后,想要分别获得每个卖家的信息。主要是卖家的名字和价格。

价格是从返回信息中就有了:

                <Offer>
                    <OfferAttributes>
                        <Condition>New</Condition>
                    </OfferAttributes>
                    <OfferListing>
                        <OfferListingId>ErBLas%2B7TSZ%2BZ%2BiFVOa5ylIp1VH8lz%2BiQ%2FsnhfzHRulMaCZLKoeZHJd%2B1TFz3IDbtjsZcDmYV11DKEmqd5i3ArRZ8D%2FBCVblaq4SYOZrc1Y%3D</OfferListingId>
                        <Price>
                            <Amount>10199</Amount>
                            <CurrencyCode>USD</CurrencyCode>
                            <FormattedPrice>$101.99</FormattedPrice>
                        </Price>
                        <AmountSaved>
                            <Amount>2101</Amount>
                            <CurrencyCode>USD</CurrencyCode>
                            <FormattedPrice>$21.01</FormattedPrice>
                        </AmountSaved>
                        <PercentageSaved>17</PercentageSaved>
                        <Availability>Usually ships in 24 hours</Availability>
                        <AvailabilityAttributes>
                            <AvailabilityType>now</AvailabilityType>
                            <MinimumHours>0</MinimumHours>
                            <MaximumHours>0</MaximumHours>
                        </AvailabilityAttributes>
                        <IsEligibleForSuperSaverShipping>1</IsEligibleForSuperSaverShipping>
                    </OfferListing>
                </Offer>

但是卖家的名字,即Merchant的name,却没找到。

【解决过程】

1。之前自己就想到了,是不是通过Merchant的id,再去利用OfferFull,去获得对应的Merchant的name。

但是不确定。

2.参考:

Merchant Name wrong – Why

提到的:

How to get Seller Name from Amazon in ItemSearch using amazon API

果然是:

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=ItemLookup&
ItemId=B00008OE6I&
ResponseGroup=OfferFull&                 <- important
MerchantId=All&                          <- important
Condition=All&                           <- important
&Timestamp=[YYYY-MM-DDThh:mm:ssZ]
&Signature=[Request Signature]

得到对应的结果:

<Items>
    ...
    <Item>
        ...
        <Offers>
            <TotalOffers>148</TotalOffers>
            <TotalOfferPages>15</TotalOfferPages>
            <Offer>
                <Merchant>
                    <MerchantId>[Merchant Id]</MerchantId>
                    <Name>[Merchant Name]</Name>
                    ...
                </Merchant>
             ...
            </Offer>
       ...

所以自己也去试试,

后来是可以得到的merchant的name的,但是由于api更新:

https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83388313_2&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2

而取消了MerchantId了,所以无法再得到MerchantId了。

 

【总结】

最后,是用代码:

    /*
     * [Function]
     * get item offer full info
     * [Input]
     * single asin
     * eg:
     * B003F4TH6G
     * 
     * [Output]
     * offer full response info
     * 
     * [Note]
     */
    public awsOfferFullInfo awsGetOfferFullInfo(string itemAsin, int itemPage = 1)
    {
        awsOfferFullInfo offerFullInfo = new awsOfferFullInfo();

        IDictionary<string, string> reqDict = new Dictionary<string, String>();
        reqDict["Service"] = "AWSECommerceService";
        reqDict["Version"] = awsApiVersion;
        reqDict["Operation"] = "ItemLookup";
        reqDict["IdType"] = "ASIN";
        reqDict["ItemId"] = itemAsin;
        //http://docs.aws.amazon.com/AWSECommerceService/latest/DG/RG_OfferFull.html
        reqDict["ResponseGroup"] = "OfferFull";
        //https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83388313_2&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
        //reqDict["MerchantId"] = "All";

        reqDict["Condition"] = "All";

        reqDict["ItemPage"] = itemPage.ToString();

        String awsReqUrl = Sign(reqDict);
        XmlDocument xmlDocNoXmlns = awsReqUrlToXmlDoc_noXmlns(awsReqUrl);

        XmlNode itemsNode = xmlDocNoXmlns.SelectSingleNode("/ItemLookupResponse/Items");
        if (requestIsValid(itemsNode))
        {
            XmlNode itemNode = itemsNode.SelectSingleNode("./Item");

            XmlNode asinNode = itemNode.SelectSingleNode("./ASIN");
            offerFullInfo.Asin = asinNode.InnerText;

            XmlNode offerSummaryNode = itemNode.SelectSingleNode("./OfferSummary");
            if (offerSummaryNode != null)
            {
                //1. TotalNew
                XmlNode totalNewNode = offerSummaryNode.SelectSingleNode("./TotalNew");
                offerFullInfo.TotalNew = totalNewNode.InnerText; //"24"

                //2. TotalUsed
                XmlNode totalUsedNode = offerSummaryNode.SelectSingleNode("./TotalUsed");
                offerFullInfo.TotalUsed = totalUsedNode.InnerText; //"1"

                //3. TotalCollectible
                XmlNode totalCollectibleNode = offerSummaryNode.SelectSingleNode("./TotalCollectible");
                if (totalCollectibleNode != null)
                {
                    offerFullInfo.TotalCollectible = totalCollectibleNode.InnerText; //"0"
                }

                //4. TotalRefurbished
                XmlNode totalRefurbishedNode = offerSummaryNode.SelectSingleNode("./TotalRefurbished");
                if (totalRefurbishedNode != null)
                {
                    offerFullInfo.TotalRefurbished = totalRefurbishedNode.InnerText; //"0"
                }
            }

            XmlNode offersNode = itemNode.SelectSingleNode("./Offers");
            if (offersNode != null)
            {
                //5. TotalOffers
                XmlNode totalOffersNode = offersNode.SelectSingleNode("./TotalOffers");
                offerFullInfo.TotalOffers = totalOffersNode.InnerText; //"1"

                //6. TotalOfferPages
                XmlNode totalOfferPagesNode = offersNode.SelectSingleNode("./TotalOffers");
                offerFullInfo.TotalOfferPages = totalOfferPagesNode.InnerText; //"1"

                //7. process each Offer
                XmlNodeList offerNodeList = offersNode.SelectNodes("./Offer");
                if ((offerNodeList != null) && (offerNodeList.Count > 0))
                {
                    offerFullInfo.offerList = new List<awsOffer>();

                    foreach (XmlNode offerNode in offerNodeList)
                    {
                        awsOffer singleOffer = new awsOffer();

                        //(1) Merchant
                        XmlNode merchantNode = offerNode.SelectSingleNode("./Merchant");
                        if (merchantNode != null)
                        {
                            //https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83388313_2&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2
                            //so now seems no MerchantId anymore
                            //XmlNode merchantIdNode = merchantNode.SelectSingleNode("./MerchantId");
                            //if (merchantIdNode != null)
                            //{
                            //    singleOffer.MerchantId = merchantIdNode.InnerText;
                            //}

                            XmlNode merchantNameNode = merchantNode.SelectSingleNode("./Name");
                            if (merchantNameNode != null)
                            {
                                singleOffer.MerchantName = merchantNameNode.InnerText; //"B&G International"
                            }

                            offerFullInfo.offerList.Add(singleOffer);
                        }
                    }
                }
                else
                {
                    gLogger.Debug(String.Format("not found Offer List for ASIN={0}", itemAsin));
                }
            }
            else
            {
                gLogger.Debug(String.Format("not found Offers for ASIN={0}", itemAsin));
            }
        }

        return offerFullInfo;
    }

得到了结果:

<Offers>
    <TotalOffers>2</TotalOffers>
    <TotalOfferPages>1</TotalOfferPages>
    <MoreOffersUrl>http://www.amazon.com/gp/offer-listing/B003F4TH6G%3FSubscriptionId%3DAKIAJQAUAH2R4HCG63LQ%26tag%3Dcrifancom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003F4TH6G</MoreOffersUrl>
    <Offer>
        <Merchant>
            <Name>B&amp;G International</Name>
        </Merchant>
        <OfferAttributes>
            <Condition>New</Condition>
        </OfferAttributes>
        <OfferListing>
            <OfferListingId>5olWrpsQDrzXlfbNDsX0OYhUTAEFqR1BeoqsGzCm42qwupPs8OKTduttQUOZjnS%2FIy9LqtA4mSVnhzaEKp87lzTWTGB1WuZo%2FBBCo5l%2BdjoegXqhViwaYSU9%2FXFA45RCihHHtW6w3QbpKV54L%2FWITA%3D%3D</OfferListingId>
            <Price>
                <Amount>10999</Amount>
                <CurrencyCode>USD</CurrencyCode>
                <FormattedPrice>$109.99</FormattedPrice>
            </Price>
            <AmountSaved>
                <Amount>3000</Amount>
                <CurrencyCode>USD</CurrencyCode>
                <FormattedPrice>$30.00</FormattedPrice>
            </AmountSaved>
            <PercentageSaved>21</PercentageSaved>
            <Availability>Usually ships in 1-2 business days</Availability>
            <AvailabilityAttributes>
                <AvailabilityType>now</AvailabilityType>
                <MinimumHours>24</MinimumHours>
                <MaximumHours>48</MaximumHours>
            </AvailabilityAttributes>
            <IsEligibleForSuperSaverShipping>0</IsEligibleForSuperSaverShipping>
        </OfferListing>
    </Offer>
    <Offer>
        <Merchant>
            <Name>Dean.Rowbot</Name>
        </Merchant>
        <OfferAttributes>
            <Condition>Used</Condition>
        </OfferAttributes>
        <OfferListing>
            <OfferListingId>f33GbR9lXeie8Cg6au6aj%2F8ENH72QGXlxPo1pvL4HSB2Ik%2ByeHhGzQHRAL9%2FAFDhDWcKqLULu1nbQWAS2uJvUYjQ4OLkkAHW%2BWS7oUYzuvDawNCJ0JLA6d1C1eDSxFuUevjRa%2FSQjRdWhKC%2BPmD5LQ%3D%3D</OfferListingId>
            <Price>
                <Amount>10000</Amount>
                <CurrencyCode>USD</CurrencyCode>
                <FormattedPrice>$100.00</FormattedPrice>
            </Price>
            <AmountSaved>
                <Amount>3999</Amount>
                <CurrencyCode>USD</CurrencyCode>
                <FormattedPrice>$39.99</FormattedPrice>
            </AmountSaved>
            <PercentageSaved>29</PercentageSaved>
            <Availability>Usually ships in 1-2 business days</Availability>
            <AvailabilityAttributes>
                <AvailabilityType>now</AvailabilityType>
                <MinimumHours>24</MinimumHours>
                <MaximumHours>48</MaximumHours>
            </AvailabilityAttributes>
            <IsEligibleForSuperSaverShipping>0</IsEligibleForSuperSaverShipping>
        </OfferListing>
    </Offer>
        //</Offers>

 

结论是:

1.通过Condition=All,ResponseGroup=OfferFull,是可以获得对应的Merchant的Name的。

2.但是由于api更新:

https://affiliate-program.amazon.co.uk/gp/advertising/api/detail/api-changes.html?ie=UTF8&pf_rd_t=501&ref_=amb_link_83388313_2&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_p=&pf_rd_s=assoc-center-1&pf_rd_r=&pf_rd_i=assoc-api-detail-2-v2

导致取消了MerchantId,所以无法得到MerchantId。即使加了MerchantId=All,也是无效的。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量