2017-05-25 31 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

相关问题