【问题标题】:eBay API - FindItemsAdvanced call in PHP does not return any responseeBay API - PHP 中的 FindItemsAdvanced 调用不返回任何响应
【发布时间】:2012-05-02 19:00:08
【问题描述】:

我正在尝试使用 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

我的问题是进行这个简单的搜索调用时缺少什么?

【问题讨论】:

  • 如果你尝试echo file_get_contents($apicalla),你会得到任何回报吗?如果没有,那么您遇到了通信问题 - url fopen 可能被禁用,来自服务器的传出 http 请求可能被阻止,ebay 可能已将您的 IP 列入黑名单等......
  • 抱歉,它确实打印了 Marc 的内容,但我之前已经调用了 getMostBooks,而且效果似乎很好。
  • 它返回2012-05-02T19:05:05.024Z Failure Please specify a query! Please specify a query! 10.1 Error RequestError E771_CORE_BUNDLED_14784928_R1 771

标签: php xml ebay-api


【解决方案1】:

您似乎正在尝试使用 eBay 的 Shopping API,特别是 FindItemsAdvanced 调用,我认为它在很久以前已被弃用并且可能不再起作用(我不再在调用参考中看到它)。您想要做的是使用来自 eBay 的 Finding APIfindItemsAdvanced

首先,您需要稍微更改您的 API 端点和查询字符串参数(请参阅前面提到的 findItemsAdvanced 调用参考以了解详细信息,但我相信它看起来更像这样(我还没有触及我的findItemsAdvanced 至少在 6 个月内打电话,所以我没有测试过这个):

$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);

最后一点:如果您想加载在搜索结果中找到的特定商品的更多详细信息,您仍然需要使用 Shopping API(特别是 GetSingleItemGetMultipleItems 调用)。因此,您最终可能会混合使用 Shopping 和 Finding API。

【讨论】:

  • 这并没有解决问题,我认为调用字符串中缺少某些内容
  • 我得到类似2012-05-02T22:04:39.405Z Success E771_CORE_BUNDLED_14784928_R1 771 150803837554 2012-05-02T22:04:39.000Z的东西,然后是ebay URL
  • 仔细查看您的查询,我发现您实际上是在尝试使用 Shopping API 中的旧 FindItemsAdvanced,我相信它已经永远消失了。您需要使用来自 Finding API 的 findItemsAdvanced。考虑到这一点,我已经广泛更新了我的答案。
【解决方案2】:

应该是这样的:

<?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 开发者帐户并点击此链接:Test your calls with API Test Tool

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多