Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases for Web Applications Twitter example Classwork/homework: Projects.

Similar presentations


Presentation on theme: "Creating Databases for Web Applications Twitter example Classwork/homework: Projects."— Presentation transcript:

1 Creating Databases for Web Applications Twitter example Classwork/homework: Projects

2 Twitter grab request from senior Example of application involving an XML (non-relational) database Approach: –combination of researching what is available and doing your own coding –I found and could understand a wrapper around the raw Twitter API: http://thinkvitamin.com/code/how-to-get- started-with-the-twitter-api/ http://thinkvitamin.com/code/how-to-get- started-with-the-twitter-api/

3 Requirements…so far grab the latest tweets with a certain hashtag –I used a search on content so will get html5 AND #html5. Can do the restriction. do NOT include retweets and replies –I do a check on the returned results. There MAY be a better way: filter these out earlier. refresh automatically: without user action, every 30 seconds –for debugging, I set this to 5 seconds –I do this strictly 'in' HTML / with JavaScript

4 So far Mine: http://socialsoftware.purchase.edu/jeanine. meyer/twittersearch.html http://socialsoftware.purchase.edu/jeanine. meyer/twittersearch.html Danielle's much prettier version: http://socialsoftware.purchase.edu/danielle.lempp/realtime/twittersearch.html http://socialsoftware.purchase.edu/danielle.lempp/realtime/twittersearch.html

5 wrapper (helper) Downloaded from thinkvitamin.com: class.twitter.php Tester script (form): twittersearch.html Working script: twittersearch.php –makes calls to the class.twitter.php functions –filters out the items starting with RT or @ –prepares HTML for display –straight html does the refresh

6 xml versus json json is an object oriented format using -> The class.twitter.php code converts this. I just followed their example…. Sample of the XML is https://twitter.com/statuses/user_timeline/k aripatila.xml https://twitter.com/statuses/user_timeline/k aripatila.xml Note: a tweet is a status element

7 my twittersearch.php <?php header('Content-type: text/html; charset=utf-8'); require_once 'class.twitter.php'; // from http://thinkvitamin.com/code/how-to-get-started-with-the-twitter-api/ ?> Finding tweets for a specified tag function init() { window.setTimeout(function() {location.reload(true);},5000); };

8 twittersearch.php, cont. <?php $t = new twitter; $tag = $_GET['key']; print "Searching for $tag..."; $s = new summize; $data = $s->search($tag); $data = $data->results;

9 Comment $data contains any number of items. the foreach($data as $d) loops over each one giving each the name $d Each $d has properties (using the json arrow notation), including $d->text Extra credit for someone who decodes the use of regular expression replace: preg_replace Notice going into and out of php

10 foreach($data as $d){ $st2= substr($d->text,0,2); $st1 = substr($d->text,0,1); if ((strcasecmp($st2,"RT") !=0) && (strcasecmp($st1,"@")!=0)) { //case insensitive compare to RT ?> profile_image_url; ?>" alt="" /> <?php echo preg_replace('/(^|\s)@(\w+)/','\1 @\2 ', $d->text); ?> by <a href="http://twitter.com/ from_user; ?>"> from_user; ?> created_at; ?> from source); ?>

11 Classwork / homework Work on projects


Download ppt "Creating Databases for Web Applications Twitter example Classwork/homework: Projects."

Similar presentations


Ads by Google