我有这个应用程序使用PHP / XML与eBay Trading API交换数据。 它已经工作了3个星期,但从昨天开始我就无法连接了。
为简单起见,我创建了一个非常简单的脚本来测试通信,但我仍然遇到同样的问题。
//show all errors - useful whilst developing
error_reporting(E_ALL);
// these keys can be obtained by registering at http://developer.ebay.com
$production = true; // toggle to true if going against production
$compatabilityLevel = 833; // eBay API version
$siteID = 3; // siteID needed in request - US=0, UK=3, DE=77...
if ($production) {
$devID = '[devID]'; // these prod keys are different from sandbox keys
$appID = '[appID]';
$certID = '[certID]';
//set the Server to use (Sandbox or Production)
$serverUrl = 'https://api.ebay.com/ws/api.dll'; // server URL different for prod and sandbox
//the token representing the eBay user to assign the call with
$userToken = '[my_token]';
}
class eBaySession {
private $requestToken;
private $devID;
private $appID;
private $certID;
private $serverUrl;
private $compatLevel;
private $siteID;
private $verb;
/** __construct
Constructor to make a new instance of eBaySession with the details needed to make a call
Input: $userRequestToken - the authentication token fir the user making the call
$developerID - Developer key obtained when registered at http://developer.ebay.com
$applicationID - Application key obtained when registered at http://developer.ebay.com
$certificateID - Certificate key obtained when registered at http://developer.ebay.com
$useTestServer - Boolean, if true then Sandbox server is used, otherwise production server is used
$compatabilityLevel - API version this is compatable with
$siteToUseID - the Id of the eBay site to associate the call iwht (0 = US, 2 = Canada, 3 = UK, ...)
$callName - The name of the call being made (e.g. 'GeteBayOfficialTime')
Output: Response string returned by the server
*/
public function __construct($userRequestToken, $developerID, $applicationID, $certificateID, $serverUrl, $compatabilityLevel, $siteToUseID, $callName) {
$this->requestToken = $userRequestToken;
$this->devID = $developerID;
$this->appID = $applicationID;
$this->certID = $certificateID;
$this->compatLevel = $compatabilityLevel;
$this->siteID = $siteToUseID;
$this->verb = $callName;
$this->serverUrl = $serverUrl;
}
/** sendHttpRequest
Sends a HTTP request to the server for this session
Input: $requestBody
Output: The HTTP Response as a String
*/
public function sendHttpRequest($requestBody) {
//build eBay headers using variables passed via constructor
$headers = $this->buildEbayHeaders();
//initialise a CURL session
$connection = curl_init();
//set the server we are using (could be Sandbox or Production server)
curl_setopt($connection, CURLOPT_URL, $this->serverUrl);
//stop CURL from verifying the peer's certificate
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_VERBOSE, TRUE);
curl_setopt($connection, CURLOPT_TIMEOUT, 30);
//set the headers using the array of headers
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
//set method as POST
curl_setopt($connection, CURLOPT_POST, 1);
//set the XML body of the request
curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
//set it to return the transfer as a string from curl_exec
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
//Send the Request
$response = curl_exec($connection);
//close the connection
curl_close($connection);
//return the response
return $response;
}
/** buildEbayHeaders
Generates an array of string to be used as the headers for the HTTP request to eBay
Output: String Array of Headers applicable for this call
*/
private function buildEbayHeaders() {
$headers = array(
//Regulates versioning of the XML interface for the API
'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $this->compatLevel,
//set the keys
'X-EBAY-API-DEV-NAME: ' . $this->devID,
'X-EBAY-API-APP-NAME: ' . $this->appID,
'X-EBAY-API-CERT-NAME: ' . $this->certID,
//the name of the call we are requesting
'X-EBAY-API-CALL-NAME: ' . $this->verb,
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
'X-EBAY-API-SITEID: ' . $this->siteID,
);
return $headers;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>GeteBayOfficialTime</TITLE>
</HEAD>
<BODY>
<?php
//SiteID must also be set in the Request's XML
//SiteID = 0 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 3;
//the call being made:
$verb = 'GeteBayOfficialTime';
//Level / amount of data for the call to return (default = 0)
$detailLevel = 0;
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody .= '</GeteBayOfficialTimeRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
}
else { //no errors
//get the node containing the time and display its contents
$eBayTime = $responseDoc->getElementsByTagName('Timestamp');
echo '<P><B>The Official eBay Time is ', $eBayTime->item(0)->nodeValue, ' GMT</B>';
}
?>
</BODY>
</HTML>
这是输出:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>GeteBayOfficialTime</TITLE>
</HEAD>
<BODY>
* About to connect() to api.ebay.com port 443 (#0)
* Trying 66.135.211.100... * Timeout
* Trying 66.135.211.140... * Timeout
* Trying 66.211.179.150... * Timeout
* Trying 66.211.179.180... * Timeout
* Trying 66.135.211.101... * Timeout
* Trying 66.211.179.148... * Timeout
* connect() timed out!
* Closing connection #0
<P>Error sending request
事实:
有过类似问题的人吗?有什么想法吗?
谢谢!
答案 0 :(得分:1)
只是为了更新: 问题出在我的托管服务(1&amp; 1)和eBay之间。他们(1&amp; 1)告诉我eBay不时阻止一些IP地址连接到他们的API。所以我花了几天时间才能连接到eBay API,但是应用程序没有任何问题。 因此,有时值得检查您的服务器托管服务提供商,因为它们可能被阻止我的易趣。
答案 1 :(得分:0)
我确实从昨天开始看到同样的问题 - 但只在两台服务器上(一台在美国,另一台在AU),而不在其他服务器上。
要在这些服务器上复制它,它甚至不必是一个有效的请求 - 只是向https://api.ebay.com/wsapi?callname=GeteBayOfficialTime&siteid=0
发送一个HTTP GET请求,该请求应该以XML格式返回错误,但同样{{1}你得到的错误。
在不同的服务器或本地计算机上运行相同的代码会发生什么?是不是eBay开始阻止来自某些IP的请求?
Displaimer:我知道这不是一个答案,但我还不能添加评论,这可能有助于找到一个模式......