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);
}
?>