Loading ...
Sorry, an error occurred while loading the content.
 

Can't get results in php

Expand Messages
  • mike.m363
    I can t seem to get the api to return results. I am still learning php, so I think the problem is in my code. My code is as follows:
    Message 1 of 3 , May 12, 2013
      I can't seem to get the api to return results. I am still learning php, so I think the problem is in my code.

      My code is as follows:
      <html>
      <head><title>Test</title></head>
      <body>
      <form action="search.php" method="GET">
      <label for="query"> Search </label>
      <?php
      echo '<input name="query" value="' . $_GET['query'] . '">';
      ?>
      <input type="submit" value="Search">
      </form>
      </div>
      <?php

      require("OAuth.php");

      $search_term = $_GET[query];
      if ($search_term != "") {

      $cc_key = "XXXXXXX";
      $cc_secret = "XXXXXX";
      $url = "http://yboss.yahooapis.com/ysearch/web";
      $args = array();
      $args["q"] = $query;
      $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);
      print_r($results);
      }
      ?>
      </div>
      </div>


      The response I keep getting for every query is:
      stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [web] => stdClass Object ( [start] => 0 [count] => 0 [totalresults] => 0 ) ) )


      When I use the code found on the code examples page I get the correct json response for query "yahoo"

      Can someone please point me in the right direction?
    • Paymon
      Sent from my iPhone
      Message 2 of 3 , May 13, 2013
        Sent from my iPhone

        On May 12, 2013, at 10:35 PM, "mike.m363" <mike.m363@...> wrote:

        > I can't seem to get the api to return results. I am still learning php, so I think the problem is in my code.
        >
        > My code is as follows:
        > <html>
        > <head><title>Test</title></head>
        > <body>
        > <form action="search.php" method="GET">
        > <label for="query"> Search </label>
        > <?php
        > echo '<input name="query" value="' . $_GET['query'] . '">';
        > ?>
        > <input type="submit" value="Search">
        > </form>
        > </div>
        > <?php
        >
        > require("OAuth.php");
        >
        > $search_term = $_GET[query];
        > if ($search_term != "") {
        >
        > $cc_key = "XXXXXXX";
        > $cc_secret = "XXXXXX";
        > $url = "http://yboss.yahooapis.com/ysearch/web";
        > $args = array();
        > $args["q"] = $query;
        > $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);
        > print_r($results);
        > }
        > ?>
        > </div>
        > </div>
        >
        >
        > The response I keep getting for every query is:
        > stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [web] => stdClass Object ( [start] => 0 [count] => 0 [totalresults] => 0 ) ) )
        >
        >
        > When I use the code found on the code examples page I get the correct json response for query "yahoo"
        >
        > Can someone please point me in the right direction?
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
      • Rahul Hampole
        In your particular case, you are pulling the response from query in to a parameter called $search_term but then looking for a query parameter called $query. I
        Message 3 of 3 , May 13, 2013
          In your particular case, you are pulling the response from query in to a parameter called $search_term but then looking for a query parameter called $query. 

          I recommend using php.net for their intro tutorial since it is an easy way to pick the basics up. 

          Best
          BOSS Team

          From: "mike.m363" <mike.m363@...>
          Reply-To: "ysearchboss@yahoogroups.com" <ysearchboss@yahoogroups.com>
          Date: Monday, May 13, 2013 6:35 AM
          To: "ysearchboss@yahoogroups.com" <ysearchboss@yahoogroups.com>
          Subject: [ysearchboss] Can't get results in php

           

          I can't seem to get the api to return results. I am still learning php, so I think the problem is in my code.

          My code is as follows:
          <html>
          <head><title>Test</title></head>
          <body>
          <form action="search.php" method="GET">
          <label for="query"> Search </label>
          <?php
          echo '<input name="query" value="' . $_GET['query'] . '">';
          ?>
          <input type="submit" value="Search">
          </form>
          </div>
          <?php

          require("OAuth.php");

          $search_term = $_GET[query];
          if ($search_term != "") {

          $cc_key = "XXXXXXX";
          $cc_secret = "XXXXXX";
          $url = "http://yboss.yahooapis.com/ysearch/web";
          $args = array();
          $args["q"] = $query;
          $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);
          print_r($results);
          }
          ?>
          </div>
          </div>

          The response I keep getting for every query is:
          stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [web] => stdClass Object ( [start] => 0 [count] => 0 [totalresults] => 0 ) ) )

          When I use the code found on the code examples page I get the correct json response for query "yahoo"

          Can someone please point me in the right direction?

        Your message has been successfully submitted and would be delivered to recipients shortly.