Hey guys,

I was hoping to get a little insight on this issue. I recently signed up for Yahoo Boss v2, I'm not really experienced with PHP. I honestly would have used google's api but they are charging too much for the amount of searches I'll need for this project. From my understanding Google is a little more plug and play. I assumed Yahoo would be too, but it's not.

The guide gives a sample api code here:

<?php  
    require("OAuth.php");  
       
    $cc_key  = "your consumer key here";  
    $cc_secret = "your consumer secret here";  
    $url = "http://yboss.yahooapis.com/ysearch/news,web,images";  
    $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);  
    print_r($results);  
    ?>

I'm trying to attach a form to call on the API to return results. I have tried everything, I'm not sure what I'm doing wrong. My attempt is below... can anyone give me some idea? or help me solve this? Thanks in advance

<?php if ($_GET['s'] == '') { ?>
<form method="get" style="margin-bottom:30px; margin-top:20px;">
<input type="text" name="s" size="30" /> <input type="submit" value="Search" />
</form>

<?php } ?>

    <?php  


    require("OAuth.php"); 
    if ($_GET['s'] != '') {
    $thequery = urlencode($_GET['s']);
    $cc_key  = "PUT KEY HERE";
    $cc_secret = "PUT SECRET HERE";
    $url = "http://yboss.yahooapis.com/ysearch/news,web,images";  
    $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, $thequery, 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);
  }

?>

What doesn't work as expected ? Do you get errors ?

I apologize, I didn't say did I lol.

Well, I get the desired form, but when I press the button to search, it just returns a blank page. I know the api must work because when I remove the form and its query elements, it prints out information. I attached a picture of what I get without my form attempt.

The form is missing the 'action' attribute, although that should still work. Have you tried without your if statements ?

Forgot, my personal way of doing this is:

$s = (isset($_GET['s']) and !empty($_GET['s'])) ? $_GET['s'] : '';
if (empty($s))
{
  // your form
}
else
{
  // your results
}

Hey thanks for replying. Sorry I had midterms, didn't get a chance to respond sooner. So I'm working on it again, I saw your last post. I'm not quite sure how to implement this with what I have...

when I try my page is blank on load. I also tried adding the action and you are right it must not matter because it still doesn't turn any results.

I appreciate any help you can continue to offer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.