Auto Tweets : Twitt Generator


Back to programming.


moderator    (2009-07-24)

moderator

Auto Tweets : Twitt Generator

Here is a very simple script (2 PHP files) that will allow you to send tweets automatically with a PHP server (PHP5) !  This is an easy way to gain time, of course you shouldn't spam Twitter, just add your own code in auto.php to choose what and how often you want to post... With the second file, you may also use the other functions, see the readme file to learn how to use it.

auto.php
<?

include "twitter.lib.php";


$twitter_user = '';
$twitter_pass = '';

$twitt = 'This is a test';

$twitter = new Twitter($twitter_user, $twitter_pass);

$twitter->updateStatus($twitt);

?>


twitter.lib.php
<?php
/*
* Copyright (c) <2008> Justin Poliey <jdp34(at)njit.edu>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

class Twitter {
/* Username:password format string */
private $credentials;

/* Contains the last HTTP status code returned */
private $http_status;

/* Contains the last API call */
private $last_api_call;

/* Twitter class constructor */
function Twitter($username, $password) {
$this->credentials = sprintf("%s:%s", $username, $password);
}

function getPublicTimeline($format, $since_id = 0) {
$api_call = sprintf("http://twitter.com/statuses/public_timeline.%s", $format);
if ($since_id > 0) {
$api_call .= sprintf("?since_id=%d", $since_id);
}
return $this->APICall($api_call);
}

function getFriendsTimeline($format, $id = NULL, $since = NULL) {
if ($id != NULL) {
$api_call = sprintf("http://twitter.com/statuses/friends_timeline/%s.%s", $id, $format);
}
else {
$api_call = sprintf("http://twitter.com/statuses/friends_timeline.%s", $format);
}
if ($since != NULL) {
$api_call .= sprintf("?since=%s", urlencode($since));
}
return $this->APICall($api_call, true);
}

function getUserTimeline($format, $id = NULL, $count = 20, $since = NULL) {
if ($id != NULL) {
$api_call = sprintf("http://twitter.com/statuses/user_timeline/%s.%s", $id, $format);
}
else {
$api_call = sprintf("http://twitter.com/statuses/user_timeline.%s", $format);
}
if ($count != 20) {
$api_call .= sprintf("?count=%d", $count);
}
if ($since != NULL) {
$api_call .= sprintf("%ssince=%s", (strpos($api_call, "?count=") === false) ? "?" : "&", urlencode($since));
}
return $this->APICall($api_call, true);
}

function showStatus($format, $id) {
$api_call = sprintf("http://twitter.com/statuses/show/%d.%s", $id, $format);
return $this->APICall($api_call);
}

function updateStatus($status) {
$status = urlencode(stripslashes(urldecode($status)));
$api_call = sprintf("http://twitter.com/statuses/update.xml?status=%s", $status);
return $this->APICall($api_call, true, true);
}

function getReplies($format, $page = 0) {
$api_call = sprintf("http://twitter.com/statuses/replies.%s", $format);
if ($page) {
$api_call .= sprintf("?page=%d", $page);
}
return $this->APICall($api_call, true);
}

function destroyStatus($format, $id) {
$api_call = sprintf("http://twitter.com/statuses/destroy/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function getFriends($format, $id = NULL) {
// take care of the id parameter
if ($id != NULL) {
$api_call = sprintf("http://twitter.com/statuses/friends/%s.%s", $id, $format);
}
else {
$api_call = sprintf("http://twitter.com/statuses/friends.%s", $format);
}
return $this->APICall($api_call, true);
}

function getFollowers($format, $lite = NULL) {
$api_call = sprintf("http://twitter.com/statuses/followers.%s%s", $format, ($lite) ? "?lite=true" : NULL);
return $this->APICall($api_call, true);
}

function getFeatured($format) {
$api_call = sprintf("http://twitter.com/statuses/featured.%s", $format);
return $this->APICall($api_call);
}

function showUser($format, $id, $email = NULL) {
if ($email == NULL) {
$api_call = sprintf("http://twitter.com/users/show/%s.%s", $id, $format);
}
else {
$api_call = sprintf("http://twitter.com/users/show.xml?email=%s", $email);
}
return $this->APICall($api_call, true);
}

function getMessages($format, $since = NULL, $since_id = 0, $page = 1) {
$api_call = sprintf("http://twitter.com/direct_messages.%s", $format);
if ($since != NULL) {
$api_call .= sprintf("?since=%s", urlencode($since));
}
if ($since_id > 0) {
$api_call .= sprintf("%ssince_id=%d", (strpos($api_call, "?since") === false) ? "?" : "&", $since_id);
}
if ($page > 1) {
$api_call .= sprintf("%spage=%d", (strpos($api_call, "?since") === false) ? "?" : "&", $page);
}
return $this->APICall($api_call, true);
}

function getSentMessages($format, $since = NULL, $since_id = 0, $page = 1) {
$api_call = sprintf("http://twitter.com/direct_messages/sent.%s", $format);
if ($since != NULL) {
$api_call .= sprintf("?since=%s", urlencode($since));
}
if ($since_id > 0) {
$api_call .= sprintf("%ssince_id=%d", (strpos($api_call, "?since") === false) ? "?" : "&", $since_id);
}
if ($page > 1) {
$api_call .= sprintf("%spage=%d", (strpos($api_call, "?since") === false) ? "?" : "&", $page);
}
return $this->APICall($api_call, true);
}

function newMessage($format, $user, $text) {
$text = urlencode(stripslashes(urldecode($text)));
$api_call = sprintf("http://twitter.com/direct_messages/new.%s?user=%s&text=%s", $format, $user, $text);
return $this->APICall($api_call, true, true);
}

function destroyMessage($format, $id) {
$api_call = sprintf("http://twitter.com/direct_messages/destroy/%s.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function createFriendship($format, $id) {
$api_call = sprintf("http://twitter.com/friendships/create/%s.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function destroyFriendship($format, $id) {
$api_call = sprintf("http://twitter.com/friendships/destroy/%s.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function friendshipExists($format, $user_a, $user_b) {
$api_call = sprintf("http://twitter.com/friendships/exists.%s?user_a=%s&user_b=%s", $format, $user_a, $user_b);
return $this->APICall($api_call, true);
}

function verifyCredentials($format = NULL) {
$api_call = sprintf("http://twitter.com/account/verify_credentials%s", ($format != NULL) ? sprintf(".%s", $format) : NULL);
return $this->APICall($api_call, true);
}

function endSession() {
$api_call = "http://twitter.com/account/end_session";
return $this->APICall($api_call, true);
}

function updateLocation($format, $location) {
$api_call = sprintf("http://twitter.com/account/update_location.%s?location=%s", $format, $location);
return $this->APICall($api_call, true, true);
}

function updateDeliveryDevice($format, $device) {
$api_call = sprintf("http://twitter.com/account/update_delivery_device.%s?device=%s", $format, $device);
return $this->APICall($api_call, true, true);
}

function rateLimitStatus($format) {
$api_call = sprintf("http://twitter.com/account/rate_limit_status.%s", $format);
return $this->APICall($api_call, true);
}

function getArchive($format, $page = 1) {
$api_call = sprintf("http://twitter.com/account/archive.%s", $format);
if ($page > 1) {
$api_call .= sprintf("?page=%d", $page);
}
return $this->APICall($api_call, true);
}

function getFavorites($format, $id = NULL, $page = 1) {
if ($id == NULL) {
$api_call = sprintf("http://twitter.com/favorites.%s", $format);
}
else {
$api_call = sprintf("http://twitter.com/favorites/%s.%s", $id, $format);
}
if ($page > 1) {
$api_call .= sprintf("?page=%d", $page);
}
return $this->APICall($api_call, true);
}

function createFavorite($format, $id) {
$api_call = sprintf("http://twitter.com/favorites/create/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function destroyFavorite($format, $id) {
$api_call = sprintf("http://twitter.com/favorites/destroy/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function follow($format, $id) {
$api_call = sprintf("http://twitter.com/notifications/follow/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function leave($format, $id) {
$api_call = sprintf("http://twitter.com/notifications/leave/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function createBlock($format, $id) {
$api_call = sprintf("http://twitter.com/blocks/create/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function destroyBlock($format, $id) {
$api_call = sprintf("http://twitter.com/blocks/destroy/%d.%s", $id, $format);
return $this->APICall($api_call, true, true);
}

function test($format) {
$api_call = sprintf("http://twitter.com/help/test.%s", $format);
return $this->APICall($api_call, true);
}

function downtimeSchedule($format) {
$api_call = sprintf("http://twitter.com/help/downtime_schedule.%s", $format);
return $this->APICall($api_call, true);
}

private function APICall($api_url, $require_credentials = false, $http_post = false) {
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $api_url);
if ($require_credentials) {
curl_setopt($curl_handle, CURLOPT_USERPWD, $this->credentials);
}
if ($http_post) {
curl_setopt($curl_handle, CURLOPT_POST, true);
}
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
$twitter_data = curl_exec($curl_handle);
$this->http_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
$this->last_api_call = $api_url;
curl_close($curl_handle);
return $twitter_data;
}

function lastStatusCode() {
return $this->http_status;
}

function lastAPICall() {
return $this->last_api_call;
}
}
?>


readme
Twitter interface class
Justin Poliey <jdp34(at)njit.edu>
http://github.com/jdp/twitterlibphp
First release Nov 26 2007
Newest release Aug 14 2008

This is a simple interface to the Twitter API.

I've tried to keep as close as possible to the real API
calls (some had to be changed due to ambiguity), but all
of the arguments are as they are in the official docs.

For documentation, check the project wiki:

    http://github.com/jdp/twitterlibphp/wikis

Usage:
$twitter = new Twitter("username", "password");
$public_timeline_xml = $twitter->getPublicTimeline("xml");

Methods:
getPublicTimeline($format [, $since_id])
getFriendsTimeline($format [, $id [, $since ]])
getUserTimeline($format [, $id [, $count [, $since ]]])
showStatus($format, $id)
updateStatus($status)
destroyStatus($format, $id)
getReplies($format [, $page ])
getFriends($format [, $id ])
getFollowers($format [, $lite ])
getFeatured($format)
showUser($format [, $id [, $email ]])
getMessages($format [, $since [, $since_id [, $page ]]])
getSentMessages($format [, $since [, $since_id [, $page ]]])
newMessage($format, $user, $text)
destroyMessage($format, $id)
createFriendship($format, $id)
destroyFriendship($format, $id)
friendshipExists($format, $user_a, $user_b)
verifyCredentials([$format])
endSession()
updateLocation($format, $location)
updateDeliveryDevice($format, $device)
rateLimitStatus($format)
getArchive($format [, $page ])
getFavorites($format [, $id [, $page ]])
createFavorite($format, $id)
destroyFavorite($format, $id)
follow($format, $id)
leave($format, $id)
createBlock($format, $id)
destroyBlock($format, $id)
test($format)
downtimeSchedule($format)
lastStatusCode()
lastAPICall()


license
Copyright (c) <2008> Justin Poliey <jdp34(at)njit.edu>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


A great script.



(more options below)

*pagobi    (2010-05-07 04:16:54)
Auto Tweets : Twitt Generator

test test test test test


*jasose    (2010-05-08 07:38:21)
12 years ago

I want to see how this thing works!


*zomama    (2010-07-05 18:48:01)
11 years ago

hello hello hello hello hello


See also


ficgs
More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.



admin
Other websites

The following links might be less relevant, please change their ranks if you find them useful.


 Nothing found for Faq+Auto+Tweets+%3A+Tweet+Generator&amp;amp;sa=X
tweetadder > faq+

 Nothing found for Automated-unique-tweet-generator-for-twitter+Auto+Tweets+%3A+Tweet+Generator&amp;amp;ct=clnk
tweetadder

 Auto Tweet Generator - Download.com
download.cnet

The posting of advertisements, profanity, or personal attacks is...

 Nothing found for +Auto+Tweets+%3A+Tweet+Generator&amp;amp;ct=clnk
tweetadder > +

 Auto Tweet Generator Tweets Messages For you On Autopilot
forums.digitalpoint > showthread.php?t=2140806+

Word Press Auto Content Generator with MRR for $3 by...
Auto Tweet Generator Tweet Messages On Autopilot With...

 Auto Tweet Generator - Download.com
download.cnet

The posting of advertisements, profanity, or personal attacks is...

 Nothing found for Twitter-tools &amp;amp;sa=U&amp;amp;ei=TjxXT7atIueQ0AXeseDJDQ&amp;amp;ved=0CDkQFjAO&amp;amp;usg=AFQjCNFS2vWuVINbHEG...
justtweetit > twitter tools/&amp;sa=U&amp;ei=TjxXT7atIueQ0AXeseDJDQ&

 Nothing found for Twitter-tools +Auto+Tweets+%3A+Tweet+Generator&amp;amp;sa=X
justtweetit > twitter tools/+

 Nothing found for +Auto+Tweets+%3A+Tweet+Generator&amp;amp;ct=clnk
autotwitterreview > +

 The page you're looking for no longer exists - Y! Downloads
downloads.yahoo > software/windows web tools

You have chosen to report a review as abusive, do you wish to...

 We couldn't find it!
chrisjgrant.posterous

 Nothing found for &amp;amp;sa=U&amp;amp;ei=TjxXT7atIueQ0AXeseDJDQ&amp;amp;ved=0CE4QFjAV&amp;amp;usg=AFQjCNHUbdN0COiLdT2lcUqp9qK2CJhEM...
autotwitterreview > &amp;sa=U&amp;ei=TjxXT7atIueQ0AXeseDJDQ&amp;ved=

 Auto Follow Friday for Twitter (by @mrboo)
autoff > &amp;sa=U&amp;ei=TjxXT7atIueQ0AXeseDJDQ&amp;ved=0CFcQFjAY&a



Response  
 

Guest name   (option)     Register
Please sum : 462 + four  




Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
There's no trackback at the moment.