Login   Register  
PHP Classes
elePHPant
Icontem

File: pulldata.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of martin barker  >  Twitter Feed API  >  pulldata.php  >  Download  
File: pulldata.php
Role: Example script
Content type: text/plain
Description: an example for using from command line
Class: Twitter Feed API
Retrieve Twitter user time line tweets
Author: By
Last change: Added comment of how to use from command line
Date: 2012-03-19 18:00
Size: 1,496 bytes
 

Contents

Class file image Download
<?php
// to use make sure script is in location allowed by open_basedir and
// use command "php pulldata.php %username%"
// where username is set to the twitter user name
require_once("classes.php");
// get the username form the commandline paramters
$username $argv[1];

// create a new instance of the TwitterFeedAPI class
$twitterAPI = new TwitterFeedAPI();

// pass the required username to the instance of TwitterFeedAPI
$twitterAPI->setUsername($username);

// create the start task to open the output file
$startTaskId $twitterAPI->setStartTaskFunction(function(){
    
$GLOBALS['fileHandle'] = fopen($username."txt"'w');
});

// create the end task to close the output file
$endTaskId $twitterAPI->setEndTaskFunction(function(){
    
fclose($GLOBALS['fileHandle']);
});

// create the task to use the output file and write the tweet to it
$eachTweetID $twitterAPI->setEachTweetFunction(function($tweet){
    
fwrite($GLOBALS['fileHandle'], $tweet->text."\r\n\r\n");
});

// tell the API to download the API responce
// this can be rapped in error checking as it can throw TwitterConnectionFailedException
$twitterAPI->fetch_tweets();

// tell the API to begin the parser
// this can be rapped in error checking as it can throw TwitterErrorException
$twitterAPI->parse();

// unset the functions
$twitterAPI->removeEachTweetFunction($eachTweetID);
$twitterAPI->removeStartTaskFunction($startTaskId);
$twitterAPI->removeEndTaskFunction($endTaskId);
?>