亚马逊提供的用于访问产品数据的Web服务
我正在尝试从亚马逊产品API,产品图像中获取。我正在使用此Laravel Framework 11.34.2命令: <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Console; use GuzzleHttp\Client; use Illuminate\Support\Facades\Log; class FetchAmazonProductImages extends Command { protected $signature = 'fetch:amazon-images'; protected $description = 'Fetch product images and affiliate links from Amazon API'; private $client; private $accessKey; private $secretKey; private $associateTag; private $host; private $region; private $marketplace; public function __construct() { parent::__construct(); $this->client = new Client(); $this->accessKey = env('AMAZON_ACCESS_KEY'); $this->secretKey = env('AMAZON_SECRET_KEY'); $this->associateTag = env('AMAZON_ASSOCIATE_TAG'); $this->host = env('AMAZON_HOST'); $this->region = env('AMAZON_REGION'); $this->marketplace = 'www.amazon.com'; // Adjust as needed } public function handle() { $consoles = Console::all(); foreach ($consoles as $console) { $this->info("Fetching data for: {$console->name}"); $response = $this->fetchProductData($console->name); if ($response && isset($response['ItemsResult']['Items'][0]['Images']['Primary']['Large']['URL'])) { $imageUrl = $response['ItemsResult']['Items'][0]['Images']['Primary']['Large']['URL']; $affiliateLink = $response['ItemsResult']['Items'][0]['DetailPageURL']; $console->update([ 'images' => $imageUrl, 'amazon_affiliate_link' => $affiliateLink, ]); $this->info("Updated console: {$console->name}"); Log::info("Updated console: {$console->name} with image URL: {$imageUrl}"); } else { $this->error("No image found for: {$console->name}"); Log::error("No image found for: {$console->name}"); } } } private function fetchProductData($productName) { $uri = '/paapi5/searchitems'; $params = [ 'Keywords' => $productName, 'SearchIndex' => 'All', 'Resources' => ['Images.Primary.Large', 'ItemInfo.DetailPageURL'], ]; $headers = $this->getRequestHeaders($uri, $params); $body = json_encode([ 'Keywords' => $productName, 'SearchIndex' => 'All', 'Resources' => ['Images.Primary.Large', 'ItemInfo.DetailPageURL'], 'PartnerTag' => $this->associateTag, 'PartnerType' => 'Associates', 'Marketplace' => $this->marketplace, ]); try { $response = $this->client->request('POST', "https://{$this->host}{$uri}", [ 'headers' => $headers, 'body' => $body, ]); $data = json_decode($response->getBody(), true); return $data; } catch (\Exception $e) { $this->error("Error fetching product data: {$e->getMessage()}"); Log::error("Error fetching product data: {$e->getMessage()}"); return null; } } private function getRequestHeaders($uri, $params) { $date = gmdate('Ymd\THis\Z'); $signedHeaders = 'host;x-amz-date'; $canonicalHeaders = 'host:' . $this->host . "\n" . 'x-amz-date:' . $date . "\n"; $canonicalRequest = "POST\n{$uri}\n" . http_build_query($params) . "\n{$canonicalHeaders}\n{$signedHeaders}\nUNSIGNED-PAYLOAD"; $algorithm = 'AWS4-HMAC-SHA256'; $credentialScope = gmdate('Ymd') . '/' . $this->region . '/execute-api/aws4_request'; $stringToSign = "{$algorithm}\n{$date}\n{$credentialScope}\n" . hash('sha256', $canonicalRequest); $signingKey = $this->getSignatureKey(gmdate('Ymd')); $signature = hash_hmac('sha256', $stringToSign, $signingKey); $authorizationHeader = "{$algorithm} Credential={$this->accessKey}/{$credentialScope}, SignedHeaders={$signedHeaders}, Signature={$signature}"; return [ 'Content-Type' => 'application/json', 'x-amz-date' => $date, 'Authorization' => $authorizationHeader, ]; } private function getSignatureKey($date) { $kSecret = 'AWS4' . $this->secretKey; $kDate = hash_hmac('sha256', $date, $kSecret, true); $kRegion = hash_hmac('sha256', $this->region, $kDate, true); $kService = hash_hmac('sha256', 'execute-api', $kRegion, true); $kSigning = hash_hmac('sha256', 'aws4_request', $kService, true); return $kSigning; } } 我有以下错误: Error fetching product data: Unable to parse URI: https:///paapi5/searchitems 我没有为我的搜索搜索的图像。 任何建议我做错了什么? 我感谢您的答复!update 这是我的.env文件: AMAZON_ACCESS_KEY=xxxxxx AMAZON_SECRET_KEY=xxxxxx AMAZON_ASSOCIATE_TAG=product-20 AMAZON_HOST=webservices.amazon.com AMAZON_REGION=us-east-1 update2 I使用config文件夹实现了它:<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Console; use GuzzleHttp\Client; use Illuminate\Support\Facades\Log; class FetchAmazonProductImages extends Command { protected $signature = 'fetch:amazon-images'; protected $description = 'Fetch product images and affiliate links from Amazon API'; private $client; private $accessKey; private $secretKey; private $associateTag; private $host; private $region; private $marketplace; public function __construct() { parent::__construct(); $this->client = new Client(); // Use config() helper to load values from config/amazon.php $this->accessKey = config('amazon.access_key'); $this->secretKey = config('amazon.secret_key'); $this->associateTag = config('amazon.associate_tag'); $this->host = config('amazon.host'); $this->region = config('amazon.region'); $this->marketplace = 'www.amazon.com'; // Adjust as needed } public function handle() { $consoles = Console::all(); foreach ($consoles as $console) { $this->info("Fetching data for: {$console->name}"); $response = $this->fetchProductData($console->name); if ($response && isset($response['ItemsResult']['Items'][0]['Images']['Primary']['Large']['URL'])) { $imageUrl = $response['ItemsResult']['Items'][0]['Images']['Primary']['Large']['URL']; $affiliateLink = $response['ItemsResult']['Items'][0]['DetailPageURL']; $console->update([ 'images' => $imageUrl, 'amazon_affiliate_link' => $affiliateLink, ]); $this->info("Updated console: {$console->name}"); Log::info("Updated console: {$console->name} with image URL: {$imageUrl}"); } else { $this->error("No image found for: {$console->name}"); Log::error("No image found for: {$console->name}"); } } } private function fetchProductData($productName) { $uri = '/paapi5/searchitems'; $params = [ 'Keywords' => $productName, 'SearchIndex' => 'All', 'Resources' => ['Images.Primary.Large', 'ItemInfo.DetailPageURL'], ]; $headers = $this->getRequestHeaders($uri, $params); $body = json_encode([ 'Keywords' => $productName, 'SearchIndex' => 'All', 'Resources' => ['Images.Primary.Large', 'ItemInfo.DetailPageURL'], 'PartnerTag' => $this->associateTag, 'PartnerType' => 'Associates', 'Marketplace' => $this->marketplace, ]); try { $response = $this->client->request('POST', "https://{$this->host}{$uri}", [ 'headers' => $headers, 'body' => $body, ]); $data = json_decode($response->getBody(), true); return $data; } catch (\Exception $e) { $this->error("Error fetching product data: {$e->getMessage()}"); Log::error("Error fetching product data: {$e->getMessage()}"); return null; } } private function getRequestHeaders($uri, $params) { $date = gmdate('Ymd\THis\Z'); $signedHeaders = 'host;x-amz-date'; $canonicalHeaders = 'host:' . $this->host . "\n" . 'x-amz-date:' . $date . "\n"; $canonicalRequest = "POST\n{$uri}\n" . http_build_query($params) . "\n{$canonicalHeaders}\n{$signedHeaders}\nUNSIGNED-PAYLOAD"; $algorithm = 'AWS4-HMAC-SHA256'; $credentialScope = gmdate('Ymd') . '/' . $this->region . '/execute-api/aws4_request'; $stringToSign = "{$algorithm}\n{$date}\n{$credentialScope}\n" . hash('sha256', $canonicalRequest); $signingKey = $this->getSignatureKey(gmdate('Ymd')); $signature = hash_hmac('sha256', $stringToSign, $signingKey); $authorizationHeader = "{$algorithm} Credential={$this->accessKey}/{$credentialScope}, SignedHeaders={$signedHeaders}, Signature={$signature}"; return [ 'Content-Type' => 'application/json', 'x-amz-date' => $date, 'Authorization'=> $authorizationHeader, ]; } private function getSignatureKey($date) { $kSecret = 'AWS4' . $this->secretKey; $kDate = hash_hmac('sha256', $date, $kSecret, true); $kRegion = hash_hmac('sha256', $this->region, $kDate, true); $kService = hash_hmac('sha256', 'execute-api', $kRegion, true); $kSigning = hash_hmac('sha256', 'aws4_request', $kService, true); return $kSigning; } } 我仍然遇到此错误: [2025-03-09 20:47:59] local.ERROR: Error fetching product data: Client error: `POST https://webservices.amazon.com/paapi5/searchitems` resulted in a `404 Not Found` response: {"Output":{"__type":"com.amazon.coral.service#InternalFailure"},"Version":"1.0"} 我相信您缺少目标操作。 plape尝试添加X-Amz-Target: com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems标头。 在您的代码中,应在您的getRequestHeaders($uri, $params)方法中修改以下内容。 private function getRequestHeaders($uri, $params) { $date = gmdate('Ymd\THis\Z'); $signedHeaders = 'host;x-amz-date'; $canonicalHeaders = 'host:' . $this->host . "\n" . 'x-amz-date:' . $date . "\n"; $canonicalRequest = "POST\n{$uri}\n" . http_build_query($params) . "\n{$canonicalHeaders}\n{$signedHeaders}\nUNSIGNED-PAYLOAD"; $algorithm = 'AWS4-HMAC-SHA256'; $credentialScope = gmdate('Ymd') . '/' . $this->region . '/execute-api/aws4_request'; $stringToSign = "{$algorithm}\n{$date}\n{$credentialScope}\n" . hash('sha256', $canonicalRequest); $signingKey = $this->getSignatureKey(gmdate('Ymd')); $signature = hash_hmac('sha256', $stringToSign, $signingKey); $authorizationHeader = "{$algorithm} Credential={$this->accessKey}/{$credentialScope}, SignedHeaders={$signedHeaders}, Signature={$signature}"; return [ 'Content-Type' => 'application/json', 'x-amz-date' => $date, 'X-Amz-Target' => 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems', // ADD THIS ONE. 'Authorization' => $authorizationHeader, ]; }
产品出现在Amazon MWS API中,但不是产品广告API
为什么是? 我应该只使用一个或另一个原因吗?
如何使用https(awsecommercerservice)访问亚马逊图像
对于我网站上的每种产品,我都有一个页面,该页面宣传了亚马逊的几本书。我从我的Web服务器中使用查询来获得书籍来awsecommerceservice。我从亚马逊收到的XML包含A ...
我试图获得所有价格在12.50到11.50之间的产品。我正在使用
exports.search = function(req, res){ OperationHelper = require('apac').OperationHelper; var opHelper = new OperationHelper({ awsId: process.env.AMZ_ACCESS_KEY_CODE, awsSecret: process.env.AMZ_SECRET_ACCESS_KEY, assocId: process.env.AMZ_ASSOCIATE_ID }); opHelper.execute('ItemSearch', { 'SearchIndex': 'All', 'Keywords': ' ', 'MaximumPrice': 12.50, 'MinimumPrice': 11.50, 'ResponseGroup': 'Medium' }, function(error, results) { res.send(results); }); };
String requestString ="Service=AWSECommerceService" + "&Version=2013-29-03" + "&Operation=ItemSearch" + "&AssociateTag=myassociatetag" + "&SearchIndex=" +category + "&ItemPage=5" + "&Sort=relevancerank" + "&ResponseGroup=ItemAttributes,Images" + "&Keywords=" + keyword + "&Timestamp=[YYYY-MM-DDThh:mm:ssZ]" ;
import amazonproduct SECRET_KEY = 'xxx' AWS_KEY = 'yyy' api = amazonproduct.API(AWS_KEY,SECRET_KEY,'us') node = api.item_lookup('B001OXUIIG')
我想将亚马逊产品集用作其他产品的一部分。理想情况下,我们将使用移动应用程序上的图像和 ID 作为应用程序中产品的唯一标识符。 有这样的事吗……
这是我得到的回复:我们计算的请求签名与您提供的签名不匹配。 这是我用来生成签名的代码: 静态字节[] HmacSHA256(St...
Amazon API 返回奇怪的维度。在网站上,他们展示了: 产品尺寸:8.7 x 7.9 x 0.6 英寸; 1.8 盎司 运输重量:4 盎司 当 API 返回: [物品尺寸...
出于我个人的目的,我有大约 300 名各种书籍的作者(全名)。我想将此列表分为“小说作者”和“非小说作者”。如果作者两者都写,那么...
在 Amazon PAAPI 中获取 Prime Pantry 产品的任何方式
我目前正在使用 PAAPI 为制造商获取产品,但现在需要获取 Prime Pantry 物品,我不确定是否有办法做到这一点或是否可能。 使用以下响应组...
我正在尝试使用 AmazonFresh 食谱 API,它允许您指定多种成分,然后将用户重定向到亚马逊上的购物清单:https://www.amazon.com/afx/ingredients/veri。 ..