11

私はeBayAPIを初めて使用し、現在PHPで開発していますが、GetItemを使用して、アイテムIDに基づく注文の詳細を自分のWebサイトのデータベースにインポートすることができました。しかし、私が今やりたいのは、ユーザーアカウントを私のウェブサイトにリンクし、それらのリストを私のデータベースにインポートすることです。GetItemに使用したコード(以下)を配置しましたが、スタックしていて、GetAccount、GetUser、またはGetSellerListのいずれを使用すればよいかわかりません。

まず、ユーザーを自分のWebサイトからeBayにリダイレクトして、アプリケーションが自分のリストにアクセスすることを許可します。

2番目:そのリスト(今のところエコーで十分です)を私のWebサイトにインポートします。

これは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;
            }
        }
    }
4

3 に答える 3

14

API についての eBay の貧弱なドキュメントをたくさん読んだ後、気が狂いそうになりました! 私は自分の手で問題を解決し、API に関するステップバイステップのガイドを作成し、これを行う方法を見つけました。できるだけ簡単に説明しようとします。(PHPを使用)

何する:

  1. アプリケーションを作成する
  2. eBay からユーザーのセッション ID を取得する
  3. セッション ID を使用して eBay に接続する
  4. ユーザーは、自分のユーザー アカウントにリンクするためのアプリケーションへのアクセスを許可します (セッション ID を使用)
  5. ユーザートークンが生成されました
  6. 私たちのウェブサイトは、将来の使用のためにユーザートークンを受け取ります(eBayのユーザーデータにアクセスするため)

最初 に、keys.php と eBaySession.php という名前の 2 つの PHP ファイルが必要です。これらは、eBay の Developers Web サイト Documentations にある eBay の PHP SDK にあります。( https://www.x.com/developers/ebay/documentation-tools/sdks )

次に 、これら 2 つのファイルを、ユーザー インターフェイスも保持する新しい PHP ファイルに含めます。

3 番目 に、eBay の Developers Web サイトでアカウントを作成し、新しいアプリケーションを作成します。

第 4 に、開発者アカウントを使用して、アプリケーションのサンドボックス キーと製品キーを取得します。次に、サンドボックス ユーザーを生成し、ユーザー トークンを取得します。(マイアカウントページ経由)

eBay の Developers Web サイトで自分を見つけるのは少し難しいかもしれませんが、最終的にコツをつかむことができます。

第 5 に、アプリケーションの DEV、APP、CERT、および UserToken を keys.php ファイルに挿入します (プロダクション モードとサンドボックス モードの両方で)。

第6に、マイアカウントページ( RuNameの管理) にもあるRuNameが必要です。

7番目 ここで、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';
    }


?>

次に 、以下のように、ユーザー向けの出力を含む最初のページを作成します。

<?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';ため、[Link Your Ebay Account] ボタンをクリックすると、ユーザーは次の URL に送信されます。

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

RuName とセッション ID が含まれています。

9 番目 のユーザーは eBay にログインし、アプリケーションへのアクセスを許可し、Web サイトに送り返します。ここで、前の部分と同じセッション 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>

これで、アクセス権とトークンが得られました。ただし、eBay は安全な接続 (SSL) を介してのみこれらの機能を受け入れるため、これを HTTPS URL でホストするようにしてください。そうしないと、このコードの実行が困難になります。

フィードバックを受け取ることで、最終的にこの回答を改善します。少し混乱するかもしれませんが、時間が経つにつれてより良い答えになることを願っています. 必要に応じて、eBay API の GetItem 関数についても説明しました。

編集: もちろん、cUrl と XML リクエストを統合できます。

于 2013-01-04T20:34:14.113 に答える
0

@Hossein Jabbari ソリューションが機能します。したがって、基本的には ebaysession.php ファイルをダウンロードしてアプリに含める必要があります。curl/xml 部分のすべてを処理します。

アプリのすべての詳細を keys.php ファイルにプラグインします。次に、リダイレクト URL 名を作成するとき、認証が受け入れられる URL は、fetchToken 関数を持つ 2 番目の php ファイルである必要があります。最初の PHP ファイルのセッション ID をセッションに保存するので、取得は簡単です。

次に、最初の PHP ファイルに移動して、サインイン URL をクリックします。次に、本番サイトまたはサンドボックス サイトにログインし、[同意する] をクリックするとすぐに 2 番目の PHP ページにリダイレクトされ、トークンを確認できます。

于 2016-05-26T08:07:54.413 に答える
0

eBay の SDK を使用する必要はありません。または、指定した 2 つの PHP インクルード ファイル。私はあなたと同じように夢中になり、実際にいくつかの XML 作業と cURL を実行するだけの独自の SDK ファイルを作成しました。私は契約を結んでいるので、まだファイルを共有することはできませんが、わずか 170 行のコードであり、次のように eBay API 全体を使用できます。

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

したがって、ebay https://developer.ebay.com/DevZone/build-test/test-tool/default.aspxのこの API テスト ツールを使用する必要があります 。

そして、必要な呼び出しを渡してパラメーターを読み取ることができます。彼らはくだらないですが、これ以上簡単なことはありません。

繰り返しになりますが、私のコードを共有できればと思いますが、もしあなたが腰を落ち着けたら、cURL と XML 変換を少しだけ記述して、SDK なしで API を「文字通り」使用できることをお知らせします。

Amazon MWS api と google docs api についても同じことを行いました。できるだけ早くこれらすべてを共有できることを願っています

于 2013-07-15T01:57:59.390 に答える