eBay API returns "GeteBayTime" 在此版本中无效或不受支持

eBay API returns "GeteBayTime" is invalid or not supported in this release

这是我在 eBay 上的第一次测试 API。 我附上了我正在使用的代码,它给了我以下错误:

2016-02-13 11:10:22FailureUnsupported API call.The API call "GeteBayTime" is invalid or not supported in this release.2ErrorRequestError92117790382

代码:

$EndPoint='https://api.sandbox.ebay.com/ws/api.dll';

$header= array(
    '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: ' . 'GeteBayTime',
    'X-EBAY-API-SITEID: ' . '101',
    'X-EBAY-API-REQUEST-ENCODING:XML'
);

$xml='<?xml version="1.0" encoding="utf-8"?>
<GeteBayTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">
</GeteBayTimeRequest>';

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

你能告诉我哪里错了吗? 谢谢

交易操作的名称叫做 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. The example below shows how to use the SDK to call GeteBayOfficalTime. There are more 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'));
}