eBay API 返回的“GeteBayTime”在此版本中无效或不受支持


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

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

2016-02-13 11:10:22失败不支持的 API 调用。API 调用"GeteBayTime"在此版本中无效或不受支持。2错误请求错误92117790382

法典:

$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。在代码中将 GeteBayTime 替换为 GeteBayOfficalTime 将使其正常工作。此外,由于您正在调用交易操作,因此您需要将您的 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; 

如果你有兴趣,我已经为PHP开发了一个SDK。下面的示例展示了如何使用 SDK 调用 GeteBayOfficalTime。还有更多可用示例

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'));
}