Continue with behavioral marketing. Tweets.
Reports.
Homework: capture tweets project.
Reports
• Identify 5 cookies: owner & data
• How accurate was the geolocation program for you using …
Capturing tweets• Background: request from senior project student• I found a wrapper for the official Application
Programming Interface (API)http://twitter.slawcup.com/twitter.class.phps
http://thinkvitamin.com/code/how-to-get-started-with-the-twitter-api/
– I downloaded and then uploaded to my site– NOTE: I did not bother to study/understand the whole thing!
• ASSIGNMENT for you (you can work in teams): build your own twitter capture program.– Probably will require you to work with incomplete understanding
(like I did).
Client - Server
• HTML5 JavaScript program to run on the client, invokes
• php program to run on the server, which accesses
• twitter programs
Another Purchase server
• Was not necessary, but I have had to put other php programs on socialsoftware.purchase.edu so I put these there, also.
• Why?– Server programs can … change programs,
files on server, so CTS restricts certain operations.
• reading & writing & uploading files
Quick overview php
• A php program (script) on server– takes input from the html script that invoked it,
most typically form input– does something: often invoking SQL on a
database, and here invoking programs on twitter
– creates html to send back to browser, to be interpreted in normal way.
NOTICE
• Upload to server and test.
• NO test on your own computer– unless….
• You can't see the source of a php program, but only the source of the html it produces
php quirks
• Variables start with $• -> used for associative array components
– similar to dot notation in JavaScript. More when we do JSON
• . (dot) is used for concatenation• Use combination of single and double quotation,
along with \ for producing strings with quotation marks.
• Go into and out of php. Everything 'outside of php' is part of the html document sent to the browser.
My twitter example(s)
• html presents a form. Invokes php script
• php uses wrapper functions to get data– NOT instantaneous. Need to set up to wait for
data
• php uses data to produce (echo) html.
Capture tweets
• http://socialsoftware.purchase.edu/jeanine.meyer/twittersearch.html
• http://socialsoftware.purchase.edu/jeanine.meyer/twittersearchfilter.html
• Note: Danielle's program is much nicer than mine!
• Note: she wanted the program to repeat…
<?phpheader('Content-type: text/html; charset=utf-8');require_once 'class.twitter.php';?><html><head><title>Finding tweets for a specified tag</title><script>function init() {
window.setTimeout(function() {location.reload(true);},5000);
};</script> </head>
<?php$t = new twitter;$tag = $_GET['key'];print "Searching for $tag...";$s = new summize;$data = $s->search($tag);$data = $data->results;?><?php 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
?>
<li><img src="<?php echo $d->profile_image_url; ?>"
alt="" /><?php echo preg_replace('/(^|\s)@(\w+)/','\1<a
href="http://twitter.com/\2">@\2</a>', $d->text); ?>
<em>by</em><a href="http://twitter.com/<?php echo $d-
>from_user; ?>"><?php echo $d->from_user; ?></a><?php echo $d->created_at; ?> <em>from</em>
<?php echo html_entity_decode($d->source); ?></li>
<?php }} ?></ul> </body></html>
Homework
• Create new folder on your students.purchase.edu site
• download from moodle and then upload the class.twitter.php file plus my two files
• test• NOW make changes!
– you may always search for the same thing or put in a choice or ….
– you can change what is displayed.• You also can search and find other twitter helper
programs.