PHP Classes

File: pulldata.php

Recommend this page to a friend!
  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: 4 years ago
Size: 1,496 bytes


Class file image Download
// 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
// 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

// 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(){

// 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

// tell the API to begin the parser
// this can be rapped in error checking as it can throw TwitterErrorException

// unset the functions