gpt4 book ai didi

c# - 如何使用亚马逊网络服务获取 "The Offer Listing"?

转载 作者:太空宇宙 更新时间:2023-11-03 15:46:24 27 4
gpt4 key购买 nike

我想使用亚马逊 API 获取“offer-listing”。我自己探索过,但没有得到它的线索。如果有人向我建议 API 端点以获取报价列表或替代方案,那就太好了

最佳答案

您可以取消产品页面或使用亚马逊产品的 API 并调用:

  1. GetLowestOfferListingsForSKU 获取包含您自己的报价列表(您可以使用 $request->setExcludeMe(TRUE) 排除您自己)
  2. GetMyPriceForSKU 仅获取您的报价 list

此 API 调用将返回着陆价格、运费、 list 价格,其中着陆价格是您的销售价格 + 运费。以上 API 调用均不包含卖家名称或任何身份,因此如果您需要卖家名称和售价,最好取消产品页面。

这是我使用的代码:

$asin amazon product's ASIN
$sku is amazon product's SKU
$pos_data array contains all Amazon API's credentials
$fba_check is 'Y' or 'N' whether the ASIN is FBA(Fulfilled by Amazon) or not

function init_pro_api($asin, $sku, $pos_data, $fba_check)
{
$try = 0;
while($try < 2)
{
$offers_list = "";
$AWS_ACCESS_KEY_ID = $pos_data['azn_access_key'];
$AWS_SECRET_ACCESS_KEY = $pos_data['azn_secret_access_key'];
$APPLICATION_NAME = $pos_data['azn_app_name'];
$APPLICATION_VERSION = $pos_data['azn_app_version'];
$MERCHANT_ID = $pos_data['azn_merchant_id'];
$MARKETPLACE_ID = $pos_data['azn_marketplace_id'];
$platform = $pos_data['azn_platform_variant'];


if($platform == "uk")
{
$serviceURL = "https://mws.amazonservices.co.uk/Products/2011-10-01";
}
else
$serviceURL = "https://mws-eu.amazonservices.com/Products/2011-10-01";

$DATE_FORMAT = "Y-m-d";

$config = array(
'ServiceURL' => $serviceURL,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);

$service = new MarketplaceWebServiceProducts_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $APPLICATION_NAME, $APPLICATION_VERSION, $config);

// Get My Price
$request = new MarketplaceWebServiceProducts_Model_GetMyPriceForSKURequest();
$request->setSellerId($MERCHANT_ID);
$request->setMarketplaceId($MARKETPLACE_ID);

$sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
$sku_list->setSellerSKU($sku);
$request->setSellerSKUList($sku_list);

$my_offer = invokeGetMyPriceForSKU($service, $request, $fba_check);

// Get Other Sellers Lowest Offering Price
$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForSKURequest();
$request->setSellerId($MERCHANT_ID);
$request->setMarketplaceId($MARKETPLACE_ID);
$request->setItemCondition("New");
$request->setExcludeMe(TRUE);

$sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
$sku_list->setSellerSKU($sku);
$request->setSellerSKUList($sku_list);

$other_low_offers = invokeGetLowestOfferListingsForSKU($service, $request);

if($my_offer != "" or $my_offer != NULL)
{
$offers_list["MyOffer"] = $my_offer;
}

if($other_low_offers != "" or $other_low_offers != NULL)
{
$offers_list["OtherOffer"] = $other_low_offers;
}

if(isset($offers_list["OtherOffer"][0]))
if($offers_list["OtherOffer"][0] != "")
break;
$try++;
}
return $offers_list;
}
function invokeGetMyPriceForSKU(MarketplaceWebServiceProducts_Interface $service, $request, $fba_check)
{
try
{
$my_response_data = "";
$pre_check_xml_data = array();
$xml_feed_counter = 0;
$response = $service->GetMyPriceForSKU($request);

$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$xml_data = $dom->saveXML();

$doc = new DOMDocument;
$doc->preserveWhiteSpace = FALSE;
$doc->loadXML($xml_data);
$offer_length = $doc->getElementsByTagName('Offer')->length;
$fba_index = "";
$normal_index = "";

for($o = 0; $o < $offer_length; $o++)
{
$pre_check_xml_data[$o]["LandedPrice"] = $doc->getElementsByTagName('LandedPrice')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["ListingPrice"] = $doc->getElementsByTagName('ListingPrice')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["Shipping"] = $doc->getElementsByTagName('Shipping')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["FulfillmentChannel"] = $doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue;
if($fba_check == "Y")
{
if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "AMAZON")
{
$fba_index = $o;
break;
}
}
elseif($fba_check == "N")
{
if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "MERCHANT")
{
$normal_index = $o;
break;
}
}
}
if($fba_check == "Y")
{
if($fba_index === "")
{
$my_response_data[0]["LandedPrice"] = "";
$my_response_data[0]["ListingPrice"] = "";
$my_response_data[0]["Shipping"] = "";
$my_response_data[0]["Fulfillment"] = "";
return $my_response_data;
}
else
{
$my_response_data[0] = $pre_check_xml_data[$fba_index];
return $my_response_data;
}
}
else
{
$my_response_data[0] = $pre_check_xml_data[$normal_index];
return $my_response_data;
}
}
catch(MarketplaceWebServiceProducts_Exception $ex)
{
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
function invokeGetLowestOfferListingsForSKU(MarketplaceWebServiceProducts_Interface $service, $request)
{
try
{
$response_data = "";
$counter = 0;
$response = $service->getLowestOfferListingsForSKU($request);

$getLowestOfferListingsForSKUResultList = $response->getGetLowestOfferListingsForSKUResult();
foreach($getLowestOfferListingsForSKUResultList as $getLowestOfferListingsForSKUResult)
{
if($getLowestOfferListingsForSKUResult->isSetProduct())
{
$product = $getLowestOfferListingsForSKUResult->getProduct();

if($product->isSetLowestOfferListings())
{
$lowestOfferListings = $product->getLowestOfferListings();
$lowestOfferListingList = $lowestOfferListings->getLowestOfferListing();
foreach($lowestOfferListingList as $lowestOfferListing)
{
if($lowestOfferListing->isSetQualifiers())
{
$qualifiers = $lowestOfferListing->getQualifiers();

if($qualifiers->isSetFulfillmentChannel())
{
$response_data[$counter]["Fulfilled_By"] = $qualifiers->getFulfillmentChannel();
}
if($qualifiers->isSetShippingTime())
{
$shippingTime = $qualifiers->getShippingTime();
if($shippingTime->isSetMax())
{
$response_data[$counter]["ShippingTime"] = $shippingTime->getMax();
}
}
}
if($lowestOfferListing->isSetPrice())
{
$price1 = $lowestOfferListing->getPrice();
if($price1->isSetLandedPrice())
{
$landedPrice1 = $price1->getLandedPrice();
if($landedPrice1->isSetAmount())
{
$response_data[$counter]["LandedPrice"] = $landedPrice1->getAmount();
}
}
if($price1->isSetListingPrice())
{
$listingPrice1 = $price1->getListingPrice();
if($listingPrice1->isSetAmount())
{
$response_data[$counter]["ListingPrice"] = $listingPrice1->getAmount();
}
}
if($price1->isSetShipping())
{
$shipping1 = $price1->getShipping();
if($shipping1->isSetAmount())
{
$response_data[$counter]["Shipping"] = $shipping1->getAmount() . "\n";
}
}
}
$counter++;
}
}
}
if($getLowestOfferListingsForSKUResult->isSetError())
{
$error = $getLowestOfferListingsForSKUResult->getError();
if($error->isSetMessage())
{
$response_data = $error->getMessage() . "\n";
}
}
}
return $response_data;
}
catch(MarketplaceWebServiceProducts_Exception $ex)
{
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
}
}

关于c# - 如何使用亚马逊网络服务获取 "The Offer Listing"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27934735/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com