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

孤者浪人 提交于 2020-01-01 17:03:48

问题


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>';
}

The output of that is:

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.

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").


回答1:


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

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

A few notes:

  • 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!




回答2:


Thank you for filing a support request.

I believe, you are looking for an authentication mechanism by which ebay users can authenticate your application to make API calls on their behalf. If this is the case, you have to use the Auth and Auth process, which is infact very simple.

  1. Generate an RuName through your developer account; this is a one time process and your application needs just one RuName.
  2. Make a GetSessionID API call using your key set and passing your RuName in the request
  3. Your application should open a browser window with the following URL : https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&runame=$runame&SessID=$sessionid , Please note that this URL contains the SessionID generated in Step 2 and your RuName.
  4. The user of the application should enter their ebay login credentials and once logged in, Click on I agree button.
  5. Make a FetchToken API call, which returns a token for the ebay user. Use this token to make any other Trading API call to access the ebay user account.

The above process is explained in the following knowledge base article titled, Auth and Auth Quickstart: https://ebay.custhelp.com/app/answers/detail/a_id/1198 (If you search in the same knowledge base you can find sample auth and auth implementation for Java, PHP and .Net)

Here's more detailed information on the Auth and Auth process: http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-MultipleUsers.html#GettingaTokenviaFetchToken

Here's an article on generating RuName: http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Tokens-SettingUpApp.html#GenerateanRuNameforYourApplication

Please let me know if this helps or if you need further assistance.

Best Regards, eBay Developer Support



来源:https://stackoverflow.com/questions/16502207/connecting-to-ebay-trading-api-through-soapclient-throws-the-web-service-ebayap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!