私は、大学のプロジェクトで eBay API を使用して、さまざまな単純な検索エンジンを eBay アイテムに実装しています。検索ボックスを含む単純な index.php ファイルがあります。
<form action="MySample1.php" method="POST">
<input type="text" name="query" size="90" maxlength="255" />
<input type="submit" value="Cerca" />
</FORM>
結果を表示するための sample.php ファイル。sample.php ファイルは、関数 findItemsByKeywordsResults を次のように実装します。
<?php
session_start();
error_reporting(E_ALL); // Turn on all errors, warnings and notices for easier debugging
// API request variables
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call
$s_endpoint = "http://open.api.ebay.com/shopping?"; // Shopping URL to call
$m_endpoint = 'http://svcs.ebay.com/MerchandisingService?'; // Merchandising URL to call
$version = '1.0.0'; // API version supported
$appid = 'ed-7877-4e90-a4b4-bc6d897f71c3'; // Generated via My Account to ebay developer
$globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$responseEncoding = 'XML'; // Type of response we want back
$cellColor = "bgcolor=\"#dfefff\""; // Light blue background used for selected items
$_SESSION['query'] = $_POST['query'];
function findItemsByKeywordsResults($selectedItemID = '', $cellColor = '') {
$query= $_SESSION['query'];
$safequery = urlencode( $query); // Make the query URL-friendly
global $endpoint;
global $appid;
global $responseEncoding;
global $version;
global $globalid;
global $sort;
$results = "<FORM ACTION=\"" . $_SERVER['PHP_SELF'] . "\" METHOD=\"POST\"> \n";
$results .= "<FIELDSET>\n<LEGEND>Sort by: </LEGEND>\n";
$results .= "<SELECT NAME=\"Order\" onchange=\"this.form.submit();\"> \n";
$results .= "<OPTION VALUE=\"BestMatch\" SELECTED=\"selected\"> Best Match </OPTION> \n";
$results .= "<OPTION VALUE=\"BidCountFewest\" > Bid Count Ascending </OPTION> \n";
$results .= "<OPTION VALUE=\"BidCountMost\"> Bid Count Descending </OPTION> \n";
$results .= "<OPTION VALUE=\"PricePlusShippingLowest\" > Price + Shipping Ascending </OPTION> \n";
$results .= "<OPTION VALUE=\"PricePlusShippingHighest\"> Price + Shipping Descending </OPTION> \n";
$results .= "</SELECT> \n </FIELDSET> \n";
$results .= "</FORM> \n";
// Construct the findItemsByKeywords HTTP GET call
$apicall = "$endpoint?";
$apicall .= "OPERATION-NAME=findItemsByKeywords";
$apicall .= "&SERVICE-VERSION=$version";
$apicall .= "&SECURITY-APPNAME=$appid";
$apicall .= "&GLOBAL-ID=$globalid";
$apicall .= "&sortOrder=$sort";
$apicall .= "&keywords=$safequery";
$apicall .= "&paginationInput.entriesPerPage=10";
// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicall);
// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
$results .= '';
// If the response was loaded, parse it and build links
$results .= "<h2>These are the results for <i>". $_SESSION['Query'] ."</i> </h2>\n";
$results .= "<!-- start table in findItemsByKeywordsResults --> \n";
$results .= "<table width=\"60%\" cellpadding=\"5\" border=\"1\">";
//for each item node build a table cell and append it to $results
foreach($resp->searchResult->item as $item){
// Set the cell color blue for the selected most watched item
if ($selectedItemID == $item->itemId) {
$thisCellColor = $cellColor;
} else {
$thisCellColor = '';
}
// Determine which price to display
if ($item->sellingStatus->currentPrice) {
$price = $item->sellingStatus->currentPrice;
} else {
$price = $item->listingInfo->buyItNowPrice;
}
// For each item, create a cell with imageURL, viewItemURL, watchCount, currentPrice
$results .= "<tr> \n<td $thisCellColor valign=\"top\"> \n";
$results .= "<img src=\"$item->galleryURL\"></td> \n";
$results .= "<td $thisCellColor valign=\"top\"> <p><a href=\"" . $item->viewItemURL . "\">" . $item->title . "</a></p>\n";
$results .= 'Shipped to: <b>' . $item->shippingInfo->shipToLocations . "</b><br> \n";
$results .= 'Current price: <b>$' . $price . "</b><br><br> \n";
$results .= "<FORM ACTION=\"" . $_SERVER['PHP_SELF'] . "\" METHOD=\"POST\"> \n";
$results .= "<INPUT TYPE=\"hidden\" NAME=\"Selection\" VALUE=\"$item->itemId\"> \n";
$results .= "<INPUT TYPE=\"submit\" NAME=\"$item->itemId\" ";
$results .= "VALUE=\"Get Details and Similar Items\"> \n";
$results .= "</FORM> \n";
$results .= "</td> </tr> \n\n";
}
$results .= "</tr></table> \n<!-- finish table --> \n";
}
// If the response does not indicate 'Success,' print an error
else {
$results = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
$results .= "AppID for the Production environment.</h3>";
}
return $results;
}//end of the function
まあ、最初は正しい結果が得られます。並べ替えフォームを使用して結果を並べ替え、ページをリロードしようとすると、問題が発生します。私が見つけたエラーは次のとおりです。
注意: 未定義のインデックス: C:\xampp\htdocs\GettingStarted\Sample.php の 23 行目のクエリ
誰かがこの問題を解決するのを手伝ってくれませんか??