是否可以通过 API 以编程方式获取 eBay 类别列表?
我的目标是以编程方式获取 eBay 类别列表。
GetCategories 方法似乎只能从 Trading API 中使用。如果我理解正确的话,登录交易 API 需要用户交互: http://developer.ebay.com/DevZone/XML/docs /HowTo/Tokens/GettingTokens.html
是否有另一种方法以编程方式获取 eBay 类别列表?
我使用 Drupal 7,所以使用 PHP。
My goal is to get a list of eBay categories programmatically.
It appears that the GetCategories method is only available from the Trading API. If I understand correctly, there is user interaction required to log into the Trading API:
http://developer.ebay.com/DevZone/XML/docs/HowTo/Tokens/GettingTokens.html
Is there another method to get the eBay categories list programmatically?
I'm using Drupal 7, so PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要令牌即可获取类别。您所需要的只是您的应用程序 ID
下面包含您的应用程序 ID 的链接将返回来自站点的 XML 类别列表:英国 (siteid=3)
设置 CategoryID=-1 从根级别启动列表,您可以从任何类别开始,
只需使用 IncludeSelector=ChildCategories 来获取子项
http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=YOUR-APP-ID&siteid=3&CategoryID=-1&version=729&IncludeSelector=ChildCategories
现在只需使用 SimpleXML 或其他任何东西来解析即可。
You do not need a token to get the categories. All you need is your App-ID
The link below with your APP-ID will return the XML category listing from site: UK (siteid=3)
Setting CategoryID=-1 starts the list at the root level, you can start from any category,
just use IncludeSelector=ChildCategories to get children
http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=YOUR-APP-ID&siteid=3&CategoryID=-1&version=729&IncludeSelector=ChildCategories
Now just use SimpleXML or whatever to parse.
这在当时可能是正确的,但是 API 中的此调用现在仅返回一个级别的类别,而不是整个层次结构。要对整个网站执行此操作,在一个请求(可能会变得相当大)中,您需要使用带有有效 Ebay 令牌的 GetCategories 调用,并指定
ReturnAll
和true
。另请注意,您需要定期更新这些内容,并在 Ebay 过期时提供映射算法,并随着时间的推移将类别重新映射到新名称/ID。
This may have been correct at the time, however this call in the API now only returns you one level of categories, not the entire hierarchy. To do it for a whole site, in one request (which can get quite large) you need to use the GetCategories call with a valid Ebay token, and specify
<DetailLevel>ReturnAll</DetailLevel>
and<ViewAllNodes>true</ViewAllNodes>
.Also note you will need to update these regularly and provide a mapping algorithm as Ebay expires and remaps categories to new names / ids over time.
您可以使用以下 url 获取顶级类别列表。获得类别列表后,您可以检查 [LeafCategory] 是 true 还是 false。如果类别为 true,您可以通过指定 categoryParentId 再次获取子类别。您可以使用php Curl获取结果,然后可以使用simple_xml_object获取返回的xml响应
<代码>
$url= 'http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=YOUR-APP-ID&siteid=3&CategoryID=-1&version=729&IncludeSelector=ChildCategories';
$sXML = download_page($url);
$oXML = simplexml_load_string($sXML);
print_r($oXML);退出;
函数 download_page($path){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue =curl_exec($ch);
卷曲_关闭($ch);
返回$retValue;
}
You can use the following url to get the top level category list. Once you get the list of the categories, you can check if [LeafCategory] is true or false. If it is true for the category, you can again fetch the sub-category by specifying the categoryParentId. You can use the php Curl to get the results and then you can use simple_xml_object to fetch the returned xml response
$url= 'http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=YOUR-APP-ID&siteid=3&CategoryID=-1&version=729&IncludeSelector=ChildCategories';
$sXML = download_page($url);
$oXML = simplexml_load_string($sXML);
print_r($oXML);exit;
function download_page($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}