gpt4 book ai didi

php - 通过 SoapClient 连接到 eBay Trading API 抛出 'The web service eBayAPI is not properly configured or not found and is disabled' 异常

转载 作者:行者123 更新时间:2023-12-03 23:02:18 25 4
gpt4 key购买 nike

我正在尝试连接到 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 函数的第一个参数(“命名空间”)中应该包含什么。

最佳答案

经过几个小时破解其他人的例子并自己尝试新东西后,我终于能够让这个工作起来。我在这里发布解决方案以防它帮助其他人:

$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 block 中
  • siteid参数设置为0,表示这是美国ebay网站
  • 位置 URL 应从 api.sandbox.ebay.com 更改为 api.ebay.com 以使用生产环境而不是沙箱
  • 我决定下载 WSDL 文件而不是远程使用它,因为它非常大(大约 5MB)并且会显着降低请求速度

我不知道为什么像这样的简单示例在任何地方都不可用,但我真希望在我试图解决这个问题的时候就有它!

关于php - 通过 SoapClient 连接到 eBay Trading API 抛出 'The web service eBayAPI is not properly configured or not found and is disabled' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com