2017-05-25 34 views
0

我想通過使用eBay交易API獲取sessionid。我能夠通過使用捲曲,但一旦成功獲取會話ID,因爲我嘗試通過狂飲HTTP客戶端來獲取會話ID,從易趣Ebay使用GuzzleHttp客戶端v6時不支持的API調用錯誤

FailureUnsupported API call.The API調用「GeteBayOfficialTime」得到以下錯誤響應 無效或在此release.2ErrorRequestError18131002

我想有一些問題,我使用GuzzleHttp客戶端的方式不支持。我目前使用GuzzleHttp v6,並且新增了這個功能。下面是我使用得到會話ID代碼通過調用函數actionTest

公共職能actionTest(){

$requestBody1 = '<?xml version="1.0" encoding="utf-8" ?>'; 
$requestBody1 .= '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">'; 
$requestBody1 .= '<Version>989</Version>'; 
$requestBody1 .= '<RuName>test_user-TestAs-Geforc-ldlnmtua</RuName>';  
$requestBody1 .= '</GetSessionIDRequest>'; 


$headers = $this->getHeader(); 


     $client = new Client(); 

    $request = new Request('POST','https://api.sandbox.ebay.com/ws/api.dll',$headers,$requestBody1); 
    $response = $client->send($request); 

    /*$response = $client->post('https://api.sandbox.ebay.com/ws/api.dll', [ 
     'headers' => $headers, 
     'body' => $requestBody1 
    ]);*/ 

    echo $response->getBody();die; 

} 

public function getHeader() 
{ 
    $header = array(
     'Content-Type: text/xml', 
     'X-EBAY-API-COMPATIBILITY-LEVEL: 989', 
     'X-EBAY-API-DEV-NAME: a4d749e7-9b22-441e-8406-d3b65d95d41a', 
     'X-EBAY-API-APP-NAME: TestUs-GeforceI-SBX-345ed4578-10122cfa', 
     'X-EBAY-API-CERT-NAME: PRD-120145f62955-96aa-4d748-b1df-6bf4', 
     'X-EBAY-API-CALL-NAME: GetSessionID', 
     'X-EBAY-API-SITEID: 203', 
    ); 
    return $header; 
} 

PLZ建議在我想提出請求的方式可能的缺點。我已經通過參考各種參考站點和guzzle官方文檔來嘗試/修改了請求調用請求,但錯誤仍然一樣。

回答

1

documentation中所述,您需要傳遞標題的關聯數組。

public function getHeader() 
{ 
    return [ 
     'Content-Type'     => 'text/xml', 
     'X-EBAY-API-COMPATIBILITY-LEVEL' => '989', 
     'X-EBAY-API-DEV-NAME'   => '...', 
     'X-EBAY-API-APP-NAME'   => '...', 
     'X-EBAY-API-CERT-NAME'   => '...', 
     'X-EBAY-API-CALL-NAME'   => '...', 
     'X-EBAY-API-SITEID'    => '203', 
    ]; 
} 

如果您有興趣,可以使用簡化代碼的SDK。下面顯示瞭如何調用GetSessionID的示例。

<?php 
require __DIR__.'/vendor/autoload.php'; 

use \DTS\eBaySDK\Trading\Services\TradingService; 
use \DTS\eBaySDK\Trading\Types\GetSessionIDRequestType; 

$service = new TradingService([ 
    'credentials' => [ 
     'appId' => 'your-sandbox-app-id', 
     'certId' => 'your-sandbox-cert-id', 
     'devId' => 'your-sandbox-dev-id' 
    ], 
    'siteId'  => '203', 
    'apiVersion' => '989', 
    'sandbox'  => true 
]); 

$request = new GetSessionIDRequestType(); 
$request->RuName = '...'; 

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

echo $response->SessionID; 
+0

謝謝,它的工作..標題信息是錯誤的..它必須是一個關聯數組。仍然想知道代碼如何與CURL請求一起正常工作.. – user2334930

相關問題