Etsy API 通过活跃列表而不是用户配置文件定位区域

Etsy API target region through active listings instead of user profile

玩 Etsy 的 API 文档没有在 listings 下列出任何我已经能够使用的东西,这将允许某人编码请求,如:

$apistateloc = 'florida'; 
$apiurl = 'https://openapi.etsy.com/v2/listings/active?api_key=' . $apikey . '&limit=' . $apilimit . '&region=' . $apistateloc;

API确实提到了Associations but even after looking at the associations it would appear after testing the region can be pulled from the userProfile

$userprofile = json_decode(file_get_contents('https://openapi.etsy.com/v2/users/' . $product->user_id . '/profile?api_key=' . $apikey));
$products[$i]["region"] = $userprofile->results[0]->region;

和以上作品。我认为 Region 的 API 参考会允许这样做:

$theRegion = json_decode(file_get_contents('https://openapi.etsy.com/v2/private/regions?api_key=' . $apikey));
$products[$i]["region_state"] = $theRegion->results[0]->region_name;

但每次我 运行 它都会得到以下结果:

"region_state":"European Union"

在 Etsy API 中有没有一种方法可以定位 florida 等区域的所有活动列表 (https://openapi.etsy.com/v2/listings/active)?我正在尝试提出一个基于州、国家或城市的 JSON 请求。

Region:

Represents a collection of countries to which an item ships.

因此:

$theRegion = json_decode(file_get_contents('https://openapi.etsy.com/v2/private/regions?api_key=' . $apikey));
$products[$i]["region_state"] = $theRegion->results[0]->region_name;

您所做的只是return列出可能的区域。 return 正文实际上是这样的:

{
  "region_id": 11,
  "region_name": "European Union",
  "is_dead": false
},
 {
  "region_id": 12,
  "region_name": "Europe non-EU",
  "is_dead": false
},
 {
  "region_id": 13,
  "region_name": "South America",
  "is_dead": true
},
 {
  "region_id": 14,
  "region_name": "Africa",
  "is_dead": true
},
 {
  "region_id": 15,
  "region_name": "Central America",
  "is_dead": true
}

所以 results[0] 是第一项 return,因此总是得到 European Union

您想使用 Region 而不是 location parameter。因此,您的第一个请求字符串将完美运行——只需将区域替换为位置,如下所示:

$apistateloc = 'florida'; 
$apiurl = 'https://openapi.etsy.com/v2/listings/active?api_key=' . $apikey . '&limit=' . $apilimit . '&location=' . $apistateloc;