调用Ebay API调用“GeteBayTime”无效或在此版本中不受支持

时间:2016-02-13 11:18:18

标签: php xml api call ebay

这是eBay API的首次测试。 我'附加了所需时间的代码。它给了我以下错误:

  

2016-02-13 11:10:22FailureUnsupported API调用.API调用“GeteBayTime”无效或在此版本中不受支持.2ErrorRequestError92117790382

代码:

onActivityResult()
你能告诉我哪里错了吗? 感谢

1 个答案:

答案 0 :(得分:1)

交易操作的名称称为GeteBayOfficalTime而不是GeteBayTime。在代码中用GeteBayOfficalTime替换GeteBayTime将使其工作。此外,因为您正在调用交易操作,您需要将您的eBay身份验证令牌添加到API请求中。

$devId = '<DEV ID>';
$appId = '<APP ID>';
$certId = '<CERT ID>';
$authToken = '<AUTH TOKEN>';
$endPoint = 'https://api.sandbox.ebay.com/ws/api.dll';

$header = [
    'Content-Type: text/xml',
    'X-EBAY-API-COMPATIBILITY-LEVEL:921',
    "X-EBAY-API-DEV-NAME:$devId",
    "X-EBAY-API-APP-NAME:$appId",
    "X-EBAY-API-CERT-NAME:$certId",
    'X-EBAY-API-CALL-NAME:GeteBayOfficialTime',
    'X-EBAY-API-SITEID:101',
    'X-EBAY-API-REQUEST-ENCODING:XML'
];

$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
    <RequesterCredentials xmlns="urn:ebay:apis:eBLBaseComponents">
        <eBayAuthToken>$authToken</eBayAuthToken>
    </RequesterCredentials>
</GeteBayOfficialTimeRequest>
XML;

$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $endPoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $header);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
echo $response; 

如果您有兴趣我开发了SDK for PHP。下面的示例显示了如何使用SDK调用GeteBayOfficalTime。还有更多examples available

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;

$service = new Services\TradingService([
    'apiVersion' => 921
    'siteId'     => Constants\SiteIds::IT,
    'sandbox'    => true
]);

$request = new Types\GeteBayOfficialTimeRequestType();
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $authToken;

$response = $service->geteBayOfficialTime($request);

if ($response->Ack !== 'Success') {
    if (isset($response->Errors)) {
        foreach ($response->Errors as $error) {
            printf("Error: %s\n", $error->ShortMessage);
        }
    }
} else {
    printf("The official eBay time is: %s\n", $response->Timestamp->format('H:i (\G\M\T) \o\n l jS F Y'));
}