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但即使在查看关联后,它也会在测试区域后出现,可以从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中有没有办法针对所有活动列表(https://openapi.etsy.com/v2/listings/active)定位到florida等区域? 我正在尝试发出基于州、国家或城市的 JSON 请求。

区域:

表示项目发往的国家/地区的集合。

所以有了这个:

$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_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]返回第一项,因此总是得到European Union

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

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