eBay API下载用户列表(eBay API用户指南/分步指南)


eBay API to download user listing (eBay API user guide / step by step guide)

我是eBay API的新手,目前正在PHP中开发,我已经设法使用GetItem将基于Item ID的订单详细信息导入到我网站的数据库中。但我现在要做的是链接一个用户帐户到我的网站,并导入他们的清单到我的数据库。我已经把我用于GetItem(下面)的代码,但现在我卡住了,我不知道该使用什么,GetAccount, GetUser或GetSellerList:

首先:将我的用户从我的网站重定向到eBay,以授权我的应用程序访问他/她的列表。

Second:将该列表(现在一个echo就足够了)导入到我的网站。

这是我的代码GetItem:

     require_once('keys.php');
     require_once('eBaySession.php');
    if(isset($_POST['Id']))
    {
        //Get the ItemID inputted
        $id = $_POST['Id'];

        //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 = 101;
        //the call being made:
        $verb = 'GetItem';
        ///Build the request Xml string
        $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
        $requestXmlBody .= '<GetItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
        $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";;
        $requestXmlBody .= "<ItemID>$id</ItemID>";
        $requestXmlBody .= '</GetItemRequest>';
        //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(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
            //if there is a long message (ie ErrorLevel=1), display it
            if(count($longMsg) > 0)
                echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
        }
        else //no errors
        {
            //get the nodes needed
            $titleNode = $responseDoc->getElementsByTagName('Title');
            $primaryCategoryNode = $responseDoc->getElementsByTagName('PrimaryCategory');
            $categoryNode = $primaryCategoryNode->item(0)->getElementsByTagName('CategoryName');
            $listingDetailsNode = $responseDoc->getElementsByTagName('ListingDetails');
            $startedNode = $listingDetailsNode->item(0)->getElementsByTagName('StartTime');
            $endsNode = $listingDetailsNode->item(0)->getElementsByTagName('EndTime');
            $ShippingPackageDetailsNode = $responseDoc->getElementsByTagName('ShippingPackageDetails');
            if ($ShippingPackageDetailsNode->length > 0) {
                $packageDepthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageDepth');
                $DepthUnit = $packageDepthNode->item(0)->getAttribute('unit');
                $packageLengthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageLength');
                $LengthUnit = $packageLengthNode->item(0)->getAttribute('unit');
                $packageWidthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageWidth');
                $WidthUnit = $packageWidthNode->item(0)->getAttribute('unit');
            }
            $sellingStatusNode = $responseDoc->getElementsByTagName('SellingStatus');
            $currentPriceNode = $sellingStatusNode->item(0)->getElementsByTagName('CurrentPrice');
            $currency = $currentPriceNode->item(0)->getAttribute('currencyID');
            $startPriceNode = $responseDoc->getElementsByTagName('StartPrice');
            $buyItNowPriceNode = $responseDoc->getElementsByTagName('BuyItNowPrice');
            $bidCountNode = $sellingStatusNode->item(0)->getElementsByTagName('BidCount');
            $sellerNode = $responseDoc->getElementsByTagName('Seller');
            //Display the details
            echo '<P><B>', $titleNode->item(0)->nodeValue, " ($id)</B>";
            echo '<BR>Category: ', $categoryNode->item(0)->nodeValue;
            echo '<BR>Started: ', $startedNode->item(0)->nodeValue;
            echo '<BR>Ends: ', $endsNode->item(0)->nodeValue;
            if ($ShippingPackageDetailsNode->length > 0) {
                echo "<BR>Package Length: ", $packageLengthNode->item(0)->nodeValue, ' '.$LengthUnit.'';
                echo "<BR>Package Width: ", $packageWidthNode->item(0)->nodeValue, ' '.$WidthUnit.'';
                echo "<BR>Package Depth: ", $packageDepthNode->item(0)->nodeValue, ' '.$DepthUnit.'';
            }
            echo "<P>Current Price: ", $currentPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>Start Price: ", $startPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>BuyItNow Price: ", $buyItNowPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>Bid Count: ", $bidCountNode->item(0)->nodeValue;
            //Display seller detail if present
            if($sellerNode->length > 0)
            {
                echo '<P><B>Seller</B>';
                $userIDNode = $sellerNode->item(0)->getElementsByTagName('UserID');
                $scoreNode = $sellerNode->item(0)->getElementsByTagName('FeedbackScore');
                $regDateNode = $sellerNode->item(0)->getElementsByTagName('RegistrationDate');
                echo '<BR>UserID: ', $userIDNode->item(0)->nodeValue;
                echo '<BR>Feedback Score: ', $scoreNode->item(0)->nodeValue;
                echo '<BR>Registration Date: ', $regDateNode->item(0)->nodeValue;
            }
        }
    }

在阅读了eBay上关于它的API的大量糟糕的文档后,变得疯狂!我自己动手做了一个关于API的一步一步的指南,并找到了一种方法来做到这一点。我会尽可能简单地解释。(使用PHP)

我们要做的:

  1. 创建应用
  2. 从eBay获取用户的会话ID
  3. 连接到eBay使用会话ID
  4. 用户授予访问我们的应用程序链接到他的用户帐户(使用会话ID)
  5. 生成用户令牌
  6. 我们的网站接收用户令牌以供将来使用(访问用户数据)在eBay上)
首先

您需要两个PHP文件:keys.php和eBaySession.php,它们可以在eBay的PHP SDK中找到,该SDK位于eBay的开发人员网站文档中。( https://www.x.com/developers/ebay/documentation-tools/sdks )

第二您将把这两个文件包含在一个新的PHP文件中,该文件还包含用户界面。

3 您将在eBay的开发人员网站上创建一个帐户,并创建一个新的应用程序。

第四>您将使用您的开发人员帐户获得应用程序的沙箱和生产密钥。然后,您将生成一个沙箱用户并获得一个用户令牌。(通过My Account Page)

在eBay的开发者网站上找到你自己可能有点困难,但你最终会找到它的窍门。

您将在keys.php文件中插入应用程序的DEV、APP、CERT和UserToken(用于生产模式和沙盒模式)

第六您需要一个RuName,它也位于我的帐户页面(管理您的RuNames)。

现在将RuName作为一个新参数插入到keys.php文件中:

$RuName = 'your RuName key';
所以我们的keys。php看起来像这样:
<?php
    //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 = 551;    // eBay API version
    if ($production) {
        $devID = 'production dev id';   // these prod keys are different from sandbox keys
        $appID = 'production app id';
        $certID = 'production cert id';
        $RuName = 'production RuName';
        //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 = 'production user token';
    } else {
        // sandbox (test) environment
        $devID = 'sandbox dev id';   // these prod keys are different from sandbox keys
        $appID = 'sandbox app id';
        $certID = 'sandbox cert id';
        //set the Server to use (Sandbox or Production)
        $serverUrl = 'https://api.sandbox.ebay.com/ws/api.dll';
        // the token representing the eBay user to assign the call with
        // this token is a long string - don't insert new lines - different from prod token
        $userToken = 'sandbox user token';
    }

?>

8 现在我们将构建我们的第一个页面,它为用户提供如下输出:

<?php require_once('keys.php') ?>
<?php require_once('eBaySession.php') ?>
<?php
        session_start();
        //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 = 0;
        //the call being made:
        $verb = 'GetSessionID';
        ///Build the request Xml string
        $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
        $requestXmlBody .= '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
        $requestXmlBody .= '<RuName>'.$RuName.'</RuName>';
        $requestXmlBody .= '</GetSessionIDRequest>';
        //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(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
            //if there is a long message (ie ErrorLevel=1), display it
            if(count($longMsg) > 0)
                echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
        }
        else //no errors
        {
            //get the nodes needed
            $sessionIDNode = $responseDoc->getElementsByTagName('SessionID');
            //Display the details
            $sessionID = $sessionIDNode->item(0)->nodeValue;
            $_SESSION['eBaySession'] = $sessionID;
        }
?>
<!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>Get eBay User Items</TITLE>
</HEAD>
<BODY>
<FORM action="GetItem.php" method="post">
    <h2>Testing eBay Connection Plugin</h2>
    <h3>Linking User Account to our website</h3>
    <p>Session ID: <?php echo $_SESSION['eBaySession']; ?></p>
    <BR><a href="https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&RuName=<?php echo $RuName; ?>&SessID=<?php echo $sessionID; ?>">Click Here To Link Your Ebay Account To Our Website</a>
</FORM>
</BODY>
</HTML>

这个新的PHP页面将收到一个会话ID从eBay使用$verb = 'GetSessionID';所以当我们点击"链接您的eBay帐户"按钮的用户被发送到这个URL:

https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&RuName=<?php echo $RuName; ?>&SessID=<?php echo $sessionID; ?>

包含您的RuName和会话ID。

第九用户将登录到eBay,授予访问您的应用程序,并发送回您的网站。现在,我们将使用前一部分中相同的会话ID来使用$verb = 'FetchToken';接收用户令牌(因为我们现在可以访问用户的帐户)。

<?php require_once('keys.php') ?>
<?php require_once('eBaySession.php') ?>
<!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>Get eBay User Items (Result)</TITLE>
</HEAD>
<BODY>
    <h2>Testing eBay Connection Plugin</h2>
    <h3>Receiving User Tocken</h3>
    <h4>With a User Tocken ID we can import user data to our website.</h4>
    <?php
            session_start();
            //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 = 0;
            //the call being made:
            $verb = 'FetchToken';
            ///Build the request Xml string
            $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
            $requestXmlBody .= '<FetchTokenRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
            $requestXmlBody .= '<SessionID>'.$_SESSION["eBaySession"].'</SessionID>';
            $requestXmlBody .= '</FetchTokenRequest>';
            //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(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
                //if there is a long message (ie ErrorLevel=1), display it
                echo '<BR/>User Session ID: '.$_COOKIE["eBaySession"].'';
                if(count($longMsg) > 0)
                    echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));
            }
            else //no errors
            {
                //get the nodes needed
                $eBayAuthTokenNode = $responseDoc->getElementsByTagName('eBayAuthToken');
                //Display the details
                echo '<BR/>User Session ID: '.$_SESSION["eBaySession"].'';
                echo '<BR/><BR/>User Token: '.$eBayAuthTokenNode->item(0)->nodeValue.'';
            }
    ?>
    </BODY>
    </HTML>

好了,你有访问权限和令牌。但是请确保您将此托管在HTTPS URL上,因为eBay只通过安全连接(SSL)接受这些功能。

我最终会通过收到反馈来改进这个答案。我知道这可能会让你有点困惑,但我希望我能尽快给出一个更好的答案。如果您需要的话,我还在问题中介绍了eBay API的GetItem函数。

编辑:当然你可以集成cUrl和XML请求。

您不需要使用eBay的SDK。或者你给的那两个PHP include文件。我和你一样疯狂,我做了自己的SDK文件,它只做一些XML工作和cURL。我有合同,所以我还不能分享我的文件,但它只有170行代码,你可以使用整个eBay api,如下所示

$ebay = new Ebay();
$ebay->call("ReviseItem",array(
    "ItemID"=>"1234"
));

所以你应该使用这个来自ebay的api测试工具https://developer.ebay.com/DevZone/build-test/test-tool/default.aspx

然后你可以传递任何你想要的调用并读取参数。他们是垃圾,但没有比这更容易的了。

再一次,我希望我能分享我的代码,但我只是让你知道,如果你认真,你可以写一点cURL和XML转换"字面上"使用API免费的SDK。

我已经为Amazon MWS api和google docs api做了同样的事情。我希望能尽快和大家分享这些

@Hossein Jabbari解决方案有效。所以基本上你需要下载ebaysession.php文件,并将其包含在你的应用程序中。它将为你处理所有的curl/xml部分。

将应用程序的所有细节插入到keys.php文件中。然后,当您创建一个重定向url名称时,您的认证接受的url应该是第二个具有fetchToken函数的php文件。由于您将第一个PHP文件中的会话ID存储到会话中,因此检索它应该很容易。

然后,转到第一个PHP文件,单击Sign in URL。然后,登录到生产或沙箱站点,一旦您单击ACCEPT,您将被重定向到第二个PHP页面,然后您将能够看到您的令牌。