2013-03-20 2 views
1

야후 보스 API에서이 json 출력을 얻고 있습니다. 내가 붙여 넣은 50 개 결과를 계속하지만, 첫 번째 두 ...야후 보스 API 페이지 매김

(
     [bossresponse] => stdClass Object 
      (
       [responsecode] => 200 
       [web] => stdClass Object 
      (
       [start] => 0 
       [count] => 50 
       [totalresults] => 2750000 
       [results] => Array 
        (
         [0] => stdClass Object 
          (
           [date] => 
           [clickurl] => http://www.apple.com/ipad/ 
           [url] => http://www.apple.com/ipad/ 
           [dispurl] =&gt; www.apple.com/<b>ipad</b> 
           [title] =&gt; Apple - <b>iPad</b> 
           [abstract] =&gt; <b>iPad</b> is a magical window where nothing comes between you and what you love. And it comes in two sizes. 
          ) 

         [1] =&gt; stdClass Object 
          (
           [date] =&gt; 
           [clickurl] =&gt; http://en.wikipedia.org/wiki/IPad 
           [url] =&gt; http://en.wikipedia.org/wiki/IPad 
           [dispurl] =&gt; en.wikipedia.org/wiki/<b>IPad</b> 
           [title] =&gt; <b>iPad</b> - Wikipedia, the free encyclopedia 
           [abstract] =&gt; The <b>iPad</b> is a line of tablet computers designed and marketed by Apple Inc., which runs Apple's iOS operating system. The first <b>iPad</b> was released on April 3, 2010; the ... 
          ) 

         [2] =&gt; stdClass Object 
          (
           [date] =&gt; 
           [clickurl] =&gt; http://www.amazon.com/s?ie=UTF8&amp;page=1&amp;rh=i%3Aaps%2Ck%3Aipad 
           [url] =&gt; http://www.amazon.com/s?ie=UTF8&amp;page=1&amp;rh=i%3Aaps%2Ck%3Aipad 
           [dispurl] =&gt; www.amazon.com/s?ie=UTF8&amp;page=1&amp;rh=i%3Aaps%2Ck%3A<b>ipad</b> 
           [title] =&gt; Amazon.com: <b>ipad</b> 
           [abstract] =&gt; Considering an <b>iPad</b>? Compare it to Kindle Fire HD Check out our easy side-by-side comparison chart to see how the newest <b>iPad</b> stacks up to Kindle Fire HD 8.9". 
          ) 

내가 API에 연결하고 결과를 표시 PHP에서 다음 코드를 사용하여 ...

 **//connect to yahoo api and get results in json** 
     <?php 
     require("OAuth.php"); 

    $cc_key = "**confidential**"; 
    $cc_secret = "**confidential**"; 
    $url = "http://yboss.yahooapis.com/ysearch/web"; 
    $args = array(); 
    $args["q"] = "yahoo"; 
    $args["format"] = "json"; 

    $consumer = new OAuthConsumer($cc_key, $cc_secret); 
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url, $args); 
    $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL); 
    $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args)); 
    $ch = curl_init(); 
    $headers = array($request->to_header()); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $rsp = curl_exec($ch); 
    $results = json_decode($rsp); 
    ?> 
    **// Present results in html/php** 
    <div id="resultsdiv"> 
    <?php 
    foreach($results->bossresponse->web->results as $result) 
     { 
echo '<h3><a href='.$result->url.'>'.$result->title.'</br>'.$result->abstract.'</a></h3>'; 
} 
     ?> 

제 질문은 첫 번째 웹 페이지에만 50 개의 결과가 모두 나타나므로 결과에 페이지 매김을하는 방법입니다. 모든 페이지에 10 개의 결과를 표시하고 싶습니다.

도움을 주시면 감사하겠습니다.

감사합니다.

답변

1

야후! BOSS 문서 (Universal Arguments section)는 startcount 매개 변수를 사용하여 결과의 ​​페이지 매김을 조정할 수있는 것으로 보입니다. 기본 반환 횟수는 귀하가 관찰 한 것과 일치하는 50입니다. 코드 예제에서

당신은 추가로 조정할 수 있습니다

$args["start"] = 0; // increment as needed 
$args["count"] = 10;