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


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

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

第二: 将该列表(现在回声已足够)导入我的网站。

这是我的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;
            }
        }
    }

6920
2017-12-31 17:41


起源



答案:


在eBay上阅读了很多关于它的API并且变得疯狂的糟糕文档之后!我亲自处理了问题,并逐步指导了API并找到了实现这一目标的方法。我将尝试尽可能简单地解释。 (使用PHP)

我们将要做什么:

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

第一 您需要两个名为:keys.php和eBaySession.php的PHP文件,这些文件位于eBay的PHP SDK中,该SDK位于eBay的开发者网站Documentations中。 (https://www.x.com/developers/ebay/documentation-tools/sdks

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

第三 您将在eBay的开发者网站上创建一个帐户并创建一个新的应用程序。

第四 您将使用开发人员帐户获取应用程序的沙箱和生产密钥。然后,您将生成沙箱用户并获取用户令牌。 (通过我的帐户页面

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

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

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

第七 现在,您将在keys.php文件中插入RuName作为新参数:

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


?>

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

<?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页面将从eBay使用获得会话ID $verb = 'GetSessionID'; 因此,当我们点击“链接您的易趣帐户”按钮时,用户将被发送到以下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请求。


14
2018-01-04 20:34



既然您使用了ebay API @Hossein Jabbari,请帮助我,我在哪里可以找到ebay API的secretID? - Dev DOS
嗨,很棒的答案,但我坚持第9点。我如何回到我的网站上。请指教。先谢谢你。 - Navin Nakum


答案:


在eBay上阅读了很多关于它的API并且变得疯狂的糟糕文档之后!我亲自处理了问题,并逐步指导了API并找到了实现这一目标的方法。我将尝试尽可能简单地解释。 (使用PHP)

我们将要做什么:

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

第一 您需要两个名为:keys.php和eBaySession.php的PHP文件,这些文件位于eBay的PHP SDK中,该SDK位于eBay的开发者网站Documentations中。 (https://www.x.com/developers/ebay/documentation-tools/sdks

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

第三 您将在eBay的开发者网站上创建一个帐户并创建一个新的应用程序。

第四 您将使用开发人员帐户获取应用程序的沙箱和生产密钥。然后,您将生成沙箱用户并获取用户令牌。 (通过我的帐户页面

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

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

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

第七 现在,您将在keys.php文件中插入RuName作为新参数:

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


?>

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

<?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页面将从eBay使用获得会话ID $verb = 'GetSessionID'; 因此,当我们点击“链接您的易趣帐户”按钮时,用户将被发送到以下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请求。


14
2018-01-04 20:34



既然您使用了ebay API @Hossein Jabbari,请帮助我,我在哪里可以找到ebay API的secretID? - Dev DOS
嗨,很棒的答案,但我坚持第9点。我如何回到我的网站上。请指教。先谢谢你。 - Navin Nakum


您不需要使用eBay的SDK。或者那些2 PHP包含您提供的文件。我像你一样疯了,我制作了自己的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转换''字面意思'使用免费的SDK。

亚马逊MWS apis和google docs apis也做了同样的事情。我希望能够尽快分享这一切


1
2017-07-15 01:57



是时候分享你的代码? - Hossein Jabbari
相信我,它让我无法分享它。我是公司的NDA。我正试图通过这种方式进行分享。 - Sean Clark


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

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

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


0
2018-05-26 08:07