通过SoapClient连接到eBay Trading 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

查看:127
本文介绍了通过SoapClient连接到eBay Trading API会引发“未正确配置或找不到Web服务eBayAPI并被禁用”异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到ebay交易API并使用PHP的SoapClient类发出基本请求,但遇到了麻烦。我已经花了数小时来搜索和摆弄示例,但是我什么也做不了。因此,我编写了以下准系统代码,并试图使其正常工作:

I'm trying to connect to the ebay trading API and make a basic request using PHP's SoapClient class, but I'm having trouble. I've done hours of searching for and fiddling with examples, but I cannot get anything to work. So I wrote the following barebones code and I'm trying to get it working:

$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函数的第一个参数(命名空间)应该包含什么。

Can anyone help me get this working? Part of the problem might be that I have no clue what should go in the first parameter of the SoapHeader function ("namespace").

推荐答案

经过数小时的黑客研究,并独自尝试了新的东西,我终于能够使它工作。我将解决方案发布在这里,以防其他人得到帮助:

After hours of hacking other people's examples and trying new stuff on my own, I finally was able to get this working. I'm posting the solution here in case it helps someone else:

$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 填充了适当的值。

Where the $token, $appId, and UserID are filled in with the appropriate values.

一些注意事项:


  • 由于将异常设置为true,因此SoapClient构造函数调用和所有soapCall都应放在其中尝试/捕获块

  • siteid 参数设置为 0 ,表明这是针对美国eBay网站的。

  • 位置网址应从 api.sandbox.ebay.com 更改为 api.ebay.com 使用生产环境而不是沙箱

  • 我决定下载WSDL文件,而不是远程使用它因为它很大(大约5MB),并且显着降低了请求速度

  • Because exceptions are set to true, the SoapClient constructor call and all soapCall's should be inside of a try/catch block
  • The siteid parameter is set to 0, which indicates this is for the United States ebay website
  • The location URL should be changed from api.sandbox.ebay.com to api.ebay.com to use the production environment instead of the sandbox
  • I decided to download the WSDL file instead of using it remotely because it's very large (about 5MB) and slows down requests significantly

我不知道为什么这样的简单示例没有可以在任何地方使用,但我当然希望是在我试图解决这个问题时!

I don't know why a simple example like this isn't available anywhere, but I sure wish it had been when I was trying to figure this out!

这篇关于通过SoapClient连接到eBay Trading API会引发“未正确配置或找不到Web服务eBayAPI并被禁用”异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆