Awhile ago I wrote a light Twitter PHP class that could grab and update your status. I also threw in two methods for Tiny and Tr.im url shortners. Check it out.
// DEFINE TWITTER CLASS AND UPDATE STATUS WITH OUTPUT RETURNING HTTP CODE
$run = new twitterClass();
echo $run->UpdateStatus('my message');
// TWITTER CLASS
class twitterClass {
// SET GLOBAL VARIABLES
private $twitter_username = '';
private $twitter_password = '';
private $trim_username = '';
private $trim_password = '';
// CHECK WHERE THE REQUESTING URL IS COMING FROM
public function CheckReferer(){
$url = parse_url($_SERVER["HTTP_REFERER"]);
return $url;
}
// GRAB THE RETURNED CODE FROM HTTP REQUEST AND REFERENCE DEFINITION
public function HTTP_Code($code){
switch ($code) {
case 200:
$return = "Updated!";
break;
case 301:
$return = "Moved Permanetly!";
break;
case 302:
$return = "Found!";
break;
case 304:
$return = "Not Modified!";
break;
case 307:
$return = "Temporary Redirect!";
break;
case 400:
$return = "Bad Request!";
break;
case 401:
$return = "Unauthorized!";
break;
case 403:
$return = "Forbidden!";
break;
case 404:
$return = "Not Found!";
break;
case 410:
$return = "Gone!";
break;
case 500:
$return = "Internal Server Error!";
break;
case 403:
$return = "Not Implemented!";
break;
default:
$return = "Bad Return Code! Code: $http_code_return. ";
}
return $return;
}
// REPLACE WITH Tiny URL
public function TinyURL($url){
$return = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
return $return;
}
// REPLACE WITH Tr.im URL
public function TrimURL($url){
$xml = file_get_contents("http://api.tr.im/api/trim_url.xml?url=".$url."&newtrim=yes&username=".$this->trim_username."&password=".$this->trim_password);
$return = new SimpleXMLElement($xml);
return $return->url;
}
// GET LAST STATUS UPDATE
public function LatestStatus() {
$buffer = file_get_contents("http://twitter.com/statuses/user_timeline/".$this->twitter_username.".xml?count=1");
$xml = new SimpleXMLElement($buffer);
$return = $xml->status;
return $return->text;
}
// UPDATE STATUS
public function UpdateStatus($message){
$message = urlencode($message);
$username = $this->twitter_username;
$password = $this->twitter_password;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://twitter.com/statuses/update.xml?status=$message");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$exec = curl_exec($curl);
$http_code_return = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$this->HTTP_Code($http_code_return);
curl_close($curl);
return $return;
}
}
... read more
friends
-
Verne Ho
-
Satish Kanwar
-
Brian Gilham
-
Dan Hocking
-
Nick La
-
Wes Bos
-
php simplest, cookie based, login script
Posted: Apr 16, 2010
I wrote an extremely quick and simple PHP based login script a few years back for some peers. It uses some basic methodology and cookies to authenticate. You can easily modify this script to use sessions, protect against cookie... read more -
php recursive find and replace
Posted: Apr 15, 2010
If you've ever worked with the str_replace() function in PHP you may or may not have come across the issue with it not recursively looping through arrays. I recently came across this issue when having to deal with a multi-dime... read more -
structuring your web apps files/folders
Posted: Apr 15, 2010
I'm always looking for the best way to structure my folders and files when building client apps so that I can easily navigate and update important features down the road. I've finally settled on a very streamlined approach to s... read more -
jquery collapsing nav
Posted: Apr 15, 2010
I've used this same technique a few times across a couple projects now. jQuery collapsable navs are all around the internet so if you've already seen 3-4+ you're probably not going to encounter anything new here. The basic HTML... read more
