Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
2,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <?php
  2.  
  3. // This is a simple code example, which illustrates how easy it is to not only get any YQL data rendered on a web page, but also how to call the Updates Firehose YQL Table. Follow the comments for additional help.
  4.  
  5.  
  6. // Your config file, which contains $CONSUMER_KEY & $CONSUMER_SECRET info
  7. require_once('config.php');
  8.  
  9. // grab the following library here: http://github.com/yahoo/yos-social-php5
  10. require_once('lib/OAuth/OAuth.php');
  11. require_once('lib/Yahoo/YahooOAuthApplication.class.php');
  12.  
  13. // instantiate a new oauth application, reference your credentials in config.php
  14. $oauthapp = new YahooOAuthApplication($CONSUMER_KEY, $CONSUMER_SECRET, '');
  15.  
  16. // very easily state your yql statement as a string
  17. $rsp = $oauthapp->yql('select * from social.updates.search where query="X-Men";');
  18.  
  19. // create var updates
  20. $updates = $rsp->query->results->update;
  21. ?>
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  23. "http://www.w3.org/TR/html4/loose.dtd">
  24. <html lang="en">
  25. <head>
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  27. <meta http-equiv="refresh" content="4;url=updatesfirehose.php">
  28. <title>YQL Updates Firehose Demo (YOS SDK)</title>
  29.  
  30. <style type='text/css'>
  31. /* A little lazy CSS3 magic. Sure, why not? Sadly, only works in webkit/safari, but you can do all this in FireFox too */
  32. body{font-family:verdana;font-size:11px;background:-webkit-gradient(linear, left top, left bottom, from(#000), to(#ccc), to(#000));background-color:#3D3D3D;}
  33. h1{/*text-shadow: 0.1em 0.1em 0.2em #C0C0C0;*/color:#fff;}
  34. #container{text-align:center;margin-left:auto;margin-right:auto;height:100%;}
  35. a{font-size:120%;font-weight:bold;color:#3154C7;}
  36. #results{text-align:left; width: 60%; margin-left: 15%; border: 1px solid #8D8D8D; padding: 20px; height: 600px; overflow: auto; background:#fff; }
  37. .updateitem{border:1px solid #C8C8C8;padding:20px;-moz-border-radius: 5px; -webkit-border-radius: 5px;background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#fff), color-stop(0.1, #E5E5E5), color-stop(0.5, #F2F2F2));}
  38. .sourcemini{float:right;}
  39. </style>
  40. </head>
  41. <body>
  42. <div id="container">
  43. <div id="heading"><h1>Yahoo! YQL Updates Firehose Demo</h1></div>
  44. <div id="results">
  45. <?php
  46. // Here's where the updates get built out - each item is pulled out of the array and set as a var.
  47. foreach($updates as $update) {
  48. $link = $update->link;
  49. $title = $update->title;
  50. $source = $update->source;
  51. // And render the thing.
  52. echo <<<HTML
  53. <p class='updateitem'><a href="{$link}">{$title}</a>
  54. <br><span class='sourcemini'>{$source}</span></p>
  55. HTML;
  56. }
  57. ?>
  58. </div></div>
  59. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement