2

eBay Trading API に接続し、PHP の SoapClient クラスを使用して基本的なリクエストを実行しようとしていますが、うまくいきません。例を何時間も検索していじりましたが、何も機能しません。だから私は次のベアボーンコードを書き、それを機能させようとしています:

$token  = [token here];

$client = new SOAPClient('http://developer.ebay.com/webservices/latest/eBaySvc.wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', new SoapVar(array('ebayAuthToken' => $token), SOAP_ENC_OBJECT), false);

$client->__setSoapHeaders(array($header));

$method = 'GeteBayOfficialTime';

$parameters = array(

);

try {
    $responseObj = $client->__soapCall($method, array($parameters));
}
catch (Exception $e)
{
    echo 'Exception caught. Here are the xml request & response:<br><br>';
    echo '$client->__getLastRequest():<br><pre><xmp>' . $client->__getLastRequest() . '</xmp></pre>';
    echo '$client->__getLastResponse():<br><pre><xmp>' . $client->__getLastResponse() . '</xmp></pre><br>';

    echo '<p>Exception trying to call ' . $method . '</p>';
    echo '$e->getMessage()';
    echo '<pre>' . $e->getMessage() . '</pre>';
}

その出力は次のとおりです。

Exception caught. Here are the xml request & response:

$client->__getLastRequest():

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ebay:apis:eBLBaseComponents" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Header><xsd:RequesterCredentials><ebayAuthToken>[token was here]</ebayAuthToken></xsd:RequesterCredentials></SOAP-ENV:Header><SOAP-ENV:Body><ns1:GeteBayOfficialTimeRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope>

$client->__getLastResponse():

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Server.userException</faultcode> <faultstring>com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.</faultstring> <detail/> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>


Exception trying to call GeteBayOfficialTime
$e->getMessage()

com.ebay.app.pres.service.hosting.WebServiceDisabledException: The web service eBayAPI is not properly configured or not found and is disabled.

誰でもこれを機能させるのを手伝ってもらえますか? 問題の一部は、SoapHeader 関数 (「名前空間」) の最初のパラメーターに何を入れるべきか見当がつかないことかもしれません。

4

2 に答える 2

7

他の人の例を何時間もハッキングし、自分で新しいことを試した後、ようやくこれを機能させることができました. 他の人に役立つ場合に備えて、ここにソリューションを投稿しています:

$token    = '';
$appId    = '';
$wsdl_url = 'ebaysvc.wsdl.xml'; // downloaded from http://developer.ebay.com/webservices/latest/eBaySvc.wsdl

$apiCall = 'GetUser';

$client = new SOAPClient($wsdl_url, array('trace' => 1, 'exceptions' => true, 'location' => 'https://api.sandbox.ebay.com/wsapi?callname=' . $apiCall . '&appid=' . $appId . '&siteid=0&version=821&routing=new'));

$requesterCredentials = new stdClass();
$requesterCredentials->eBayAuthToken = $token;

$header = new SoapHeader('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials', $requesterCredentials);

// the API call parameters
$params = array(
    'Version' => 821,
    'DetailLevel' => 'ReturnSummary',
    'UserID' => ''
);

$responseObj = $client->__soapCall($apiCall, array($params), null, $header);  // make the API call

$token$appIdおよびUserIDには適切な値が入ります。

いくつかのメモ:

  • 例外が true に設定されているため、SoapClient コンストラクターの呼び出しとすべての soapCall は、try/catch ブロック内にある必要があります。
  • siteidパラメータは に設定されて0います。これは、これが米国の ebay Web サイト用であることを示しています。
  • サンドボックスの代わりに本番環境を使用するには、場所の URL を から に変更する必要がありますapi.sandbox.ebay.comapi.ebay.com
  • WSDL ファイルは非常に大きく (約 5MB)、リクエストが大幅に遅くなるため、リモートで使用する代わりにダウンロードすることにしました。

このような単純な例がどこにもない理由はわかりませんが、これを理解しようとしていたときだったらよかったのにと思います!

于 2013-05-12T16:04:57.683 に答える