How to Tweet Using PHP without any Twitter App!
By Angsuman Chakraborty, Gaea News NetworkTuesday, January 13, 2009
Do you want to upgrade your site with twitter so that you can upgrade your messages each time through the site only? What big deal about that- You may ask. Well how about doing it without doing it without downloading any application! How about writing a php code which will help you to upgrade your tweets simply? Here is how.
Code
$username = 'myUserName';
$password = 'myPassword';
$status = 'This is a new Tweet!';
if ($status) {
$tweetUrl = 'https://www.twitter.com/statuses/update.xml';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($curl);
$resultArray = curl_getinfo($curl);
if ($resultArray['http_code'] == 200)
echo ‘Tweet Posted’;
else
echo ‘Could not post Tweet to Twitter right now. Try again later.’;
curl_close($curl);
}
Note:
- Change $username to YOUR username
- Change $password to YOUR password
- Edit $status to the Tweet that you want posted.
So this is it. Additionally you can add some more Javascripts that counts the amount of characters in the Tweet field and such stuff.
Happy twittering.
[Source: brownphp.com]
Tags: brownphp, Twitter, twitter using php
July 22, 2010: 4:19 pm
Why don’t you just point to the original post and script instead of passing it off as your own you stinking spammer. By the way, I’m just a guy on the internet that hates this kind of crap. The brown guys are #1 in the results so that’s right in my book. |
May 22, 2010: 3:33 pm
Hey, Anybody can help? TNX ! |
April 15, 2010: 6:44 pm
This is a great code snippet to get tweeting fast. Since you’re transmitting sensitive data (a password!) you should opt to use the SSL protected URL |
July 16, 2009: 12:36 pm
The tweeting script worked a treat! many thanks. I made small modifications and the rendering on the page made a bit of a mockery of the left and right quote character. I modified so that all fields were $_POST['fieldname']; and $status = stripcslashes($_POST['blah']); So I tweet pretty securely right off a pen drive which remains with me. BobH. |
Anti-Spammer