2016-02-13 52 views
1

這是eBay API的第一次測試。 我附上所需時間的代碼。它給了我下面的錯誤:致電Ebay API調用「GeteBayTime」在此版本中無效或不受支持

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; 

你能告訴我,我錯了嗎? 謝謝

回答

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')); 
} 
相關問題