API_PHP Posted June 27, 2013 Share Posted June 27, 2013 (edited) Good afternoon, I am able to retrieve results from yahoo with my API key, using the instructions found here: http://developer.yahoo.com/boss/search/boss_api_guide/codeexamples.html# Code: <?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); ?> However the output of results is very bizarre, for example, if I search for elephant, I get the following results (partial copy and paste): stdClass Object ( [bossresponse] => stdClass Object ( [responsecode] => 200 [images] => stdClass Object ( [start] => 0 [count] => 35 [totalresults] => 108000 [results] => Array ( [0] => stdClass Object ( [clickurl] => http://0.tqn.com/d/goafrica/1/0/Y/Q/IMG_1592.JPG [size] => 2.2MB [format] => jpeg [height] => 2432 [refererclickurl] => http://goafrica.about.com/od/africanwildlife/ss/The-Big-5-Images-Facts-And-Information-About-Africas-Big-Five_2.htm [refererurl] => http://goafrica.about.com/od/africanwildlife/ss/The-Big-5-Images-Facts-And-Information-About-Africas-Big-Five_2.htm [title] => African Elephant - One of the "Big Five" - African Elephant Image ... [url] => http://0.tqn.com/d/goafrica/1/0/Y/Q/IMG_1592.JPG [width] => 2591 [thumbnailheight] => 150 [thumbnailurl] => http://ts2.mm.bing.net/th?id=H.4700108340594617&pid=15.1&H=150&W=160 [thumbnailwidth] => 160 ) [1] => stdClass Object ( [clickurl] => http://images.nationalgeographic.com/wpf/media-live/photos/000/004/cache/african-elephant_435_600x450.jpg [size] => 54.1KB [format] => jpeg [height] => 450 [refererclickurl] => http://animals.nationalgeographic.com/animals/photos/elephants/ [refererurl] => http://animals.nationalgeographic.com/animals/photos/elephants/ [title] => Elephant Pictures - National Geographic [url] => http://images.nationalgeographic.com/wpf/media-live/photos/000/004/cache/african-elephant_435_600x450.jpg [width] => 600 [thumbnailheight] => 120 [thumbnailurl] => http://ts2.mm.bing.net/th?id=H.5058106677789309&pid=15.1&H=120&W=160 [thumbnailwidth] => 160 ) [2] => stdClass Object ( [clickurl] => http://www.splendidwallpaper.com/wp-content/uploads/2010/03/baby_elephant_1024x768.jpg [size] => 149.4KB [format] => jpeg [height] => 768 [refererclickurl] => http://www.splendidwallpaper.com/baby-elephant-2102/ [refererurl] => http://www.splendidwallpaper.com/baby-elephant-2102/ Please bear in mind that I am very new to php, and programming in general. I am completing a fast track learning course where we don`t have time to learn the basics, we are in the deep end! Does anyone have suggestions on how to display the results properly? Thanks! Note: I had tried to do it this way (which worked with the Google API - although the links were not clickable).. It did not work at all with Yahoo: foreach ($results->{ 'items' } as $item ) { echo $item->{ 'title' }.": ".$item->{ 'link' }."\n\n"; echo $newline; } Edited June 27, 2013 by API_PHP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.