douyingmou1389 2014-11-12 15:51
浏览 48
已采纳

ebay api展示来自太平洋商店的商品

I am new to api's and ebays api. What i am trying to do is select items from a spacific store on ebay (http://stores.ebay.com/Nu-Tek-Sales : or userID : machinre_nuteksalesparts)

Currently it grabs 3 random items of off ebay. I think that I am using the wrong variable for the userID b/c if i set it to anything, I get the same results. Any help in the right direction would be nice. Thank you

<!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>Merchandising Tutorial Sample</title>
<style type="text/css">body { font-family: arial,sans-serif; font-size: small; }     </style>
</head>
<body>
<?php
// Turn on all errors, warnings and notices for easier PHP debugging
error_reporting(E_ALL);

// Define global variables and settings
$m_endpoint = 'http://svcs.ebay.com/MerchandisingService?';  // Merchandising URL to call
$appid = 'My-account-ID';  // You will need to supply your own AppID
$responseEncoding = 'XML';  // Type of response we want back

// Create a function for the getMostWatchedItems call
function getMostWatchedItemsResults ($selectedItemID = '', $cellColor = '') {
global $m_endpoint;
global $appid;
global $responseEncoding;

// Construct getMostWatchedItems call with maxResults and categoryId as input
$apicalla  = "$m_endpoint";
$apicalla .= "OPERATION-NAME=getMostWatchedItems";
$apicalla .= "&SERVICE-VERSION=1.0.0";
$apicalla .= "&CONSUMER-ID=$appid";
$apicalla .= "&RESPONSE-DATA-FORMAT=$responseEncoding";
$apicalla .= "&maxResults=3";
$apicalla .= "&userID=machinre_nuteksalesparts";

// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicalla);

// Check to see if the response was loaded, else print an error
if ($resp) {
    // Set return value for the function to null
    $retna = '';

    // Verify whether call was successful
    if ($resp->ack == "Success") {

        // If there were no errors, build the return response for the function
        $retna .= "<h1>Top 3 Most Watched Items in the ";
        $retna .=  $resp->itemRecommendations->item->primaryCategoryName;
        $retna .= " Category</h1> 
";

        // Build a table for the 3 most watched items
        $retna .= "<!-- start table in getMostWatchedItemsResults --> 
";
        $retna .= "<table width=\"100%\" cellpadding=\"5\" border=\"0\"><tr> 
";

        // For each item node, build a table cell and append it to $retna
        foreach($resp->itemRecommendations->item as $item) {

            // Determine which price to display
            if ($item->currentPrice) {
                $price = $item->currentPrice;
            } else {
                $price = $item->buyItNowPrice;
            }

            // For each item, create a cell with imageURL, viewItemURL, watchCount, currentPrice
            $retna .= "<td valign=\"bottom\"> 
";
            $retna .= "<img src=\"$item->imageURL\"> 
";
            $retna .= "<p><a href=\"" . $item->viewItemURL . "\">" . $item->title . "</a></p>
";
            $retna .= 'Watch count: <b>' . $item->watchCount . "</b><br> 
";
            $retna .= 'Current price: <b>$' . $price . "</b><br><br> 
";
            $retna .= "</td> 
";
        }
        $retna .= "</tr></table> 
<!-- finish table in getMostWatchedItemsResults --> 
";

    } else {
        // If there were errors, print an error
        $retna = "The response contains errors<br>";
        $retna .= "Call used was: $apicalla";

    }  // if errors

} else {
    // If there was no response, print an error
    $retna = "Dang! Must not have got the getMostWatchedItems response!<br>";
    $retna .= "Call used was: $apicalla";
}  // End if response exists

// Return the function's value
return $retna;

} // End of getMostWatchedItemsResults function

// Display the response data
print getMostWatchedItemsResults('', '');

?>

</body>
</html>
  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看