通过SoapClient连接eBay交易API抛出'web服务eBayAPI未正确配置或未找到并被禁用'


Connecting to eBay Trading API through SoapClient throws 'The web service eBayAPI is not properly configured or not found and is disabled' exception

我正试图连接到ebay交易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函数("namespace")的第一个参数中应该包含什么。

经过几个小时的破解别人的例子和尝试自己的新东西,我终于能够让它工作。我把解决方案贴在这里,以防它对别人有帮助:

$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$appIdUserID填入相应的值

注意事项:

  • 因为异常被设置为true, SoapClient构造函数调用和所有soapCall应该在try/catch块中
  • siteid参数设置为0,表示这是针对美国ebay网站
  • 位置URL应该从api.sandbox.ebay.com更改为api.ebay.com,以使用生产环境而不是沙盒
  • 我决定下载WSDL文件而不是远程使用它,因为它非常大(大约5MB)并且显着减慢请求

我不知道为什么像这样一个简单的例子在任何地方都找不到,但我确实希望当我试图弄清楚这个问题的时候它已经存在了!

感谢您提交支持请求。

我相信,您正在寻找一种身份验证机制,通过该机制,ebay用户可以验证您的应用程序,以代表他们进行API调用。如果是这种情况,您必须使用Auth和Auth过程,这实际上非常简单。

  1. 通过你的开发者账号生成一个RuName;这是一个一次性过程,您的应用程序只需要一个RuName。
  2. 在请求中使用你的键集和传递你的RuName进行GetSessionID API调用
  3. 你的应用程序应该打开一个浏览器窗口,URL如下:https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&runame=$runame&SessID=$sessionid,请注意这个URL包含在步骤2中生成的SessionID和你的RuName。
  4. 应用程序的用户应该输入他们的ebay登录凭据,一旦登录,点击我同意按钮。
  5. 执行FetchToken API调用,为ebay用户返回令牌。使用此令牌进行任何其他交易API调用以访问ebay用户帐户。

上述过程在以下知识库文章中进行了解释,标题为Auth和Auth快速入门:https://ebay.custhelp.com/app/answers/detail/a_id/1198(如果您在相同的知识库中搜索,您可以找到Java, PHP和.Net的验证示例和验证实现)

这里有更多关于Auth和Auth过程的详细信息:http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-MultipleUsers.html#GettingaTokenviaFetchToken

这里有一篇关于生成RuName的文章:http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-SettingUpApp.html#GenerateanRuNameforYourApplication

请让我知道这是否有帮助,或者如果你需要进一步的帮助。

最诚挚的问候,eBay开发人员支持