我尝试使用 ebays 搜索 API 执行一个简单的调用,当我拨打电话时,我没有得到任何响应,问题出在实际调用本身。
$endpoint = 'http://open.api.ebay.com/shopping?';
$responseEncoding = 'XML';
$version = '631'; // API version number
$appID = 'asdf3e6e3';
$itemType = "AllItemTypes";
$itemSort = "EndTime";
//find items advanced
$apicalla = "$endpoint"
."callname=FindItemsAdvanced"
."&version=$version"
."&siteid=0"
."&appid=$appID"
."&MaxEntries=10"
."&ItemSort=EndTime"
."&ItemType=AllItemTypes"
."&IncludeSelector=SearchDetails"
."&responseencoding=$responseEncoding";
$resp = simplexml_load_file($apicalla);
此调用等效于
http://open.api.ebay.com/shopping?callname=FindItemsAdvanced&version=631&siteid=0&appid=asdf3e6e3&MaxEntries=10&ItemSort=EndTime&ItemType=AllItemTypes&IncludeSelector=SearchDetails&responseencoding=XML
我的问题是我错过了什么来进行这个简单的搜索调用?
看起来您正在尝试使用 eBay 的购物 API,特别是我认为很久以前就已弃用并且可能不再起作用的 FindItemsAdvanced
调用(我不再在调用参考中看到它(。您要做的是使用eBay的Finding API中的使用findItemsAdvanced
。
首先,您需要稍微更改一下 API 端点和查询字符串参数(有关详细信息,请参阅前面提到的 findItemsAdvanced
调用参考,但我相信它看起来会更像这样(我至少有 6 个月没有碰过我的 findItemsAdvanced
调用,所以我还没有测试过这个(:
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1?';
$responseEncoding = 'XML';
$version = '1.8.0'; // API version number (they're actually up to 1.11.0 at this point
$appID = 'asdf3e6e3';
$itemSort = "EndTimeSoonest";
//find items advanced
$apicalla = "$endpoint"
."OPERATION-NAME=findItemsAdvanced"
."&SERVICE-VERSION=$version"
."&GLOBAL-ID=EBAY-US"
."&SECURITY-APPNAME=$appID"
//."&MaxEntries=10" // look for an equivalent for this (maybe paginationInput.entriesPerPage?)
."&sortOrder=EndTimeSoonest"
//."&ItemType=AllItemTypes" // not needed AFAICT, otherwise look at itemFilterType
."&descriptionSearch=true";
."& RESPONSE-DATA-FORMAT=$responseEncoding";
$resp = simplexml_load_file($apicalla);
除此之外,要使用 findItemsAdvanced
,您必须按类别 ( categoryId
( 或关键字 ( keywords
( 指定要搜索的内容 ,因此会出现"请指定查询!
因此,您还需要添加类似以下内容的内容(假设关键字(:
$keywords = "something";
$apicalla .= "&keywords=" . urlencode($keywords);
为您提供以下内容:
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1?';
$responseEncoding = 'XML';
$version = '1.8.0'; // API version number (they're actually up to 1.11.0 at this point
$appID = 'asdf3e6e3';
$itemSort = "EndTimeSoonest";
$keywords = "something"; // make sure this is a valid keyword or keywords
//find items advanced
$apicalla = "$endpoint"
."OPERATION-NAME=findItemsAdvanced"
."&SERVICE-VERSION=$version"
."&GLOBAL-ID=EBAY-US"
."&SECURITY-APPNAME=$appID"
//."&MaxEntries=10" // look for an equivalent for this (maybe paginationInput.entriesPerPage?)
."&sortOrder=$itemSort"
//."&ItemType=AllItemTypes" // not needed AFAICT, otherwise look at itemFilterType
."&descriptionSearch=true";
."& RESPONSE-DATA-FORMAT=$responseEncoding"
."&keywords=" . urlencode($keywords);
$resp = simplexml_load_file($apicalla);
最后一点:如果你想加载你在结果中找到的特定项目的更多详细信息,你仍然需要使用购物API(特别是GetSingleItem和GetMultipleItems调用(。因此,您最终可能会混合使用购物和查找API。
它应该是这样的:
<?php
$url = 'http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.11.0&SECURITY-APPNAME=YOUR_APP_ID&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&paginationInput.entriesPerPage=2&keywords=ipod&siteid=203&GLOBAL-ID=EBAY-IN';
$xml = file_get_contents( $url );
$xml = simplexml_load_string( $url );
?>
登录您的 ebay 开发人员帐户并单击此链接:使用 API 测试工具测试您的调用
希望这有帮助。