0

使用 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;

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

$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 请求。

4

1 回答 1

2

地区

表示物品运送到的国家/地区的集合。

所以有了这个:

$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;
于 2016-03-22T23:19:42.353 回答