2013-06-04 2 views
4

이 코드가 있지만 아이템 가격이 표시되지 않습니다. 다른 모든 것 (사진 및 링크)이 작동합니다. 나는 'currentPrice'를 시도했지만 아무 것도 나타나지 않습니다. 그리고 이것은 Ebay API입니다. 나는 해결책을 찾고있는 데 약 2 시간을 보냈지 만 문서화가 잘되어 있지 않습니다.이베이 (ebay) API로 가격을받는 방법

<?php 
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; // URL to call 
$version = '1.11.0'; // API version supported by your application 
$appid  = 'myid'; // Replace with your own AppID 
$globalid = 'EBAY-US'; // Global ID of the eBay site you want to search (e.g., EBAY-DE) 
$query  = 'golf'; // You may want to supply your own query 
$safequery = urlencode($query); // Make the query URL-friendly 

// Construct the findItemsByKeywords HTTP GET call 
$apicall = "$endpoint?"; 
$apicall .= "OPERATION-NAME=findItemsAdvanced"; 
$apicall .= "&SERVICE-VERSION=$version"; 
$apicall .= "&SECURITY-APPNAME=$appid"; 
$apicall .= "&GLOBAL-ID=$globalid"; 
$apicall .= "&keywords=$safequery"; 
$apicall .= "&paginationInput.entriesPerPage=12"; 
$apicall .= "&paginationInput.pageNumber=1"; 
$apicall .= "&categoryId=1513"; 

// 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 
    foreach ($resp->searchResult->item as $item) { 
     $pic = $item->galleryURL; 
     $link = $item->viewItemURL; 
     $title = $item->title; 
     $price = $item->currentPrice; 

     // For each SearchResultItem node, build a link and append it to $results 
     $results .= "<div id='prod-wrap'><div class='prodimg-wrap' align='center'><img src=\"$pic\" class='prodimg'></div> <div class='prodtxt' align='center'><a href=\"$link\">$title</a></div><div class='price' align='center'><p class='price' align='center'>$price</p></div></div>"; 
    } 
} 
// 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>"; 
} 
?> 
<!-- Build the HTML page with values from the call response --> 
<html> 
<head> 
    <style type="text/css"> 
     body { 
      font-family: arial, sans-serif; 
     } 

     img { 
      border: none; 
     } 

     #store-wrap { 
      width: 770px; 
      height: auto; 
      position: relative; 
     } 

     #filter-wrap { 
      width:   160px; 
      float:   left; 
      height:   500px; 
      margin-right:  10px; 
      background-color: #EBEBEB; 
     } 

     #result-wrap { 
      width: 600px; 
      float: left; 
      height: auto; 
      position: relative; 
     } 

     #pagination-wrap { 
      width: 200px; 
      float: right; 
      height: 20px; 
     } 

     #prod-wrap { 
      width:   150px; 
      height:   200px; 
      margin:   0 15px 15px; 
      float:   left; 
      border:   1px solid #999999; 
      background-color: #CCCCCC; 
     } 

     .prodimg-wrap { 
      width: 150px; 
     } 

     .prodimg { 
      width: 100px; 
      height: 100px; 
      padding: 4px; 
     } 

     .prodtxt { 
      font-size: 11px; 
      width:  130px; 
      padding: 0 8px; 
     } 
     .price { 
      font-size: 11px; 
      width: 60px; 
      padding: 0 8px; 
     } 
     .price p { 
      font-size: 11px; 
      color: black; 
     } 
    </style> 
</head> 
<body> 

<h1><?php echo $query; ?></h1> 

<table> 
    <tr> 
     <td> 
      <div id="store-wrap"> 

       <div id="result-wrap"> 
        <?php echo $results;?> 

       </div> 
      </div> 
     </td> 
    </tr> 
</table> 

</body> 
</html> 
+1

루프 안에 'var_dump ($ item)'을하면 어떻게됩니까? – andrewsi

+0

@andrewsi 나는이 행이 흥미 롭다고 생각한다 : [ "sellingStatus"] => 객체 (SimpleXMLElement) # 11 (5) {[ "currentPrice"] => 문자열 (5) "34.99" – miks

답변

4

당신은 findItemsAdvanced.searchResult.item.sellingStatus

$price = $item->sellingStatus->currentPrice; 

searchResult.item.sellingStatus.currentPrice Amount (double)

와 항목이 나열되어있는 사이트의 통화에서 주어진 항목의 현재 가격을 시도 할 수 있습니다. 즉, currentPrice는 원래 리스팅 통화로 반환됩니다.

경쟁 입찰 항목 목록의 경우 currentPrice는 목록에 입찰가가없는 경우 현재 최소 입찰가 또는 목록에 입찰가가있는 경우 현재 높은 입찰가입니다. Buy It Now 가격은 currentPrice에 영향을 미치지 않습니다.

기본 고정 가격 (FixedPrice), 매장 재고 (StoreInventory), 광고 형식 (AdFormat) 및 분류 광고 (분류) 목록의 경우 currentPrice가 현재 고정 가격입니다.

+0

나는 해냈고 효과가 있었다. 감사합니다. – miks

+0

샘플 코드에서 이것이 어디에 추가되었는지 설명해주십시오. – Robin

관련 문제