You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Amazon Product API获取完整商品属性信息?

解决Amazon Product Advertising API获取特定商品属性的问题

一、核心问题说明

你提到的书籍Genre、SSD存储容量、商品Variations、"About this item"文本、Product Overview这些数据,不在默认返回的ItemInfo资源覆盖范围内,需要指定额外的资源参数,或在响应的特定节点中提取。

二、具体实现方案与代码示例

1. 获取独特属性(书籍Genre、SSD容量)

这类属性属于商品的特征属性,调用getItems时需指定Resources参数包含ItemAttributes,而非仅传ItemInfo。

PHP调用示例:

use Amazon\ProductAdvertisingAPI\v1\com\amazon\paapi5\v1\api\DefaultApi;
use Amazon\ProductAdvertisingAPI\v1\com\amazon\paapi5\v1\GetItemsRequest;
use Amazon\ProductAdvertisingAPI\v1\com\amazon\paapi5\v1\PartnerType;

// 初始化已配置凭证的API客户端
$apiInstance = new DefaultApi();
$getItemsRequest = new GetItemsRequest();
$getItemsRequest->setPartnerTag("你的PartnerTag");
$getItemsRequest->setPartnerType(PartnerType::ASSOCIATES);
$getItemsRequest->setItemIds(["B08N5WRWNW"]); // 替换为目标ASIN

// 指定需要的资源集合
$getItemsRequest->setResources([
    "ItemInfo.Title",
    "ItemAttributes.Genre", // 书籍分类字段
    "ItemAttributes.StorageCapacity" // SSD存储容量字段
]);

try {
    $response = $apiInstance->getItems($getItemsRequest);
    $item = $response->getItemsResult()->getItems()[0];
    
    // 提取书籍Genre
    if ($item->getItemAttributes() && $item->getItemAttributes()->getGenre()) {
        echo "书籍分类: " . implode(", ", $item->getItemAttributes()->getGenre()) . "\n";
    }
    // 提取SSD存储容量
    if ($item->getItemAttributes() && $item->getItemAttributes()->getStorageCapacity()) {
        echo "存储容量: " . $item->getItemAttributes()->getStorageCapacity() . "\n";
    }
} catch (Exception $e) {
    echo "调用失败: ", $e->getMessage(), "\n";
}

2. 获取商品Variations(变体)

变体数据需要指定Variations资源,添加到Resources参数中:

$getItemsRequest->setResources([
    "Variations.VariationSummary",
    "Variations.Item"
]);

// 解析变体数据
if ($item->getVariations()) {
    $variationItems = $item->getVariations()->getItem();
    echo "变体数量: " . count($variationItems) . "\n";
    foreach ($variationItems as $variation) {
        echo "变体ASIN: " . $variation->getASIN() . ", 价格: " . $variation->getOffers()->getListings()[0]->getPrice()->getAmount() . "\n";
    }
}

3. 获取"About this item"与Product Overview

这部分内容存于ItemInfo.Features节点,需指定ItemInfo.Features资源:

$getItemsRequest->setResources([
    "ItemInfo.Features"
]);

// 提取"About this item"内容
if ($item->getItemInfo() && $item->getItemInfo()->getFeatures()) {
    $features = $item->getItemInfo()->getFeatures()->getDisplayValues();
    echo "About this item:\n";
    foreach ($features as $feature) {
        echo "- " . $feature . "\n";
    }
}

注:Product Overview通常是ItemInfo.Features中的前几条内容,部分商品的结构化Overview数据可通过同时指定ItemInfo.ProductInfo资源尝试提取。

三、关键注意事项

  • 不同商品类型的属性节点存在差异:比如书籍的Genre在ItemAttributes.Genre,电子设备的技术参数可能在ItemAttributes.TechnicalInfo下,需根据商品类型调整字段。
  • 所有字段需做非空判断,避免因响应字段为null引发报错。
  • 确保API权限符合要求,部分数据需特定PartnerType或权限等级才能获取。

内容的提问来源于stack exchange,提问作者donohoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 22:40:12