How to Update Twitter using PHP and Twitter API

Posted in Tutorials • Posted on 39 Comments

In the world of socializing on internet, Twitter is a big name and for developers its Twitter’s API. Its just Twitter’s unmatchable API that is failing all other micro-blogging services (like Tumblr) out there as it allows you to do almost everything. Once you become familiar with the Twitter API you can do innumerable number of things with it like updating your Twitter statuses remotely (Hint: We’ll be making this today!), searching the latest tweets for a keyword, and grab someone’s or your latest Tweets.

Today, we’ll be making a PHP Application that helps you update your Twitter status. So let’s get started without wasting anymore time!

The PHP script we’ll be making will consist of four files:

Files Usage
Index.html Includes the form which asks for your username, password & new status.
Post-to-Twitter.php Posts the information entered on the form in Index.html to Twitter.
Style.css For Index.html
Style-php.css For Post-To-Twitter.php

MAKING THE FORM & STYLING IT WITH CSS

First, lets make a form in HTML with three input boxes for username, password & the new status message respectively and one command button which would submit the values to the PHP file “Post-to-Twitter.php”.

<html>
<head>
<title>Updating Twitter status using PHP</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1><span id="header">Updating Twitter Using PHP</span></h1></p>
<div id="quote1"><!--Start Quote1-->
<center><p> Learn to send updates to Twitter using its API + PHP! </p></center>
</div><!--End Quote1-->

<div id="form" align="center"><!--Start Form-->
<form name="form1" method="post" action="post-to-twitter.php">
<p><br />
<label>
Twitter Username:
<input name="t_user" type="text" id="t_user">
</label>
</p>

<p><br />
<label>Twitter Password:
<input name="t_pass" type="password" id="t_pass">
</label>
</p>
<p><br />
<label>Your status:</label>
</p>
<br />
<p>
<textarea name="t_update" cols="50" rows="5" id="t_update" ></textarea>
</p>
<p><br />
<label>
<input type="submit" name="Submit" value="Post To Your Twitter Account!">
</label>
</p>
</form>
</div><!--End Form-->
<div id="quote2"><!--Start Quote2-->
<center><p>NOTE: We aren't storing your passwords in any way. If you want to try this then go ahead without hesitation!</p></center>
</div><!--End Quote2-->
</body>
</html>

You might have noticed that I have already attached the form action attribute to the post-to-twitter.php file. The CSS styling for this form goes below:


body {
background-color:#fff;
font-size:0.825em;
font-family:Arial, Helvetica, sans-serif;

}

#quote1 {
margin-left:300px;
margin-right:300px;
border-style:solid;
border-width:2px;
border-color:#74DF00;
background-color:#EFEFD7;
line-height: 10px;
}

#quote2 {
margin-left:300px;
margin-right:300px;
border-style:solid;
border-width:2px;
border-color:#74DF00;
background-color:#EFEFD7;
line-height: 10px;
}

h1{
 padding:30px 0;
 text-align:center;
 text-shadow:0 1px 1px white;
 margin-bottom:30px;
 background-color:#f8f8f8;
 font-size:35px;
}

label{
text-shadow:0 1px 1px white;
font-size:18px;
}

This is what we have made till now:

SPICING THE FORM USING JQUERY

In the screenshot above, you may have seen that textboxes have a different style (when they are inactive) and this style can be brought using JQuery. The textboxes will have a different style or will be highlighted when they are active or when someone clicks on them. Just punch in the code below into the index.html file’s head and you are good to go!


<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $('input[type="text"]').addClass("idleField");
 $('input[type="text"]').focus(function(){
 $(this).removeClass("idleField").addClass("focusField");
 if (this.value == this.defaultValue){
 this.value = '';
 }
 if(this.value != this.defaultValue){
 this.select();
 }
 });
 $('input[type="password"]').addClass("idleField");
 $('input[type="password"]').focus(function(){
 $(this).removeClass("idleField").addClass("focusField");
 if (this.value == this.defaultValue){
 this.value = '';
 }
 if(this.value != this.defaultValue){
 this.select();
 }
 });
 $('textarea').addClass("idleField");
 $('textarea').focus(function(){
 $(this).removeClass("idleField").addClass("focusField");
 if (this.value == this.defaultValue){
 this.value = '';
 }
 if(this.value != this.defaultValue){
 this.select();
 }
 });
 $('input[type="text"]').blur(function(){
 $(this).removeClass("focusField").addClass("idleField");
 if ($.trim(this.value == '')){
 this.value = (this.defaultValue ? this.defaultValue : '');
 }
 });
 $('input[type="password"]').blur(function(){
 $(this).removeClass("focusField").addClass("idleField");
 if ($.trim(this.value == '')){
 this.value = (this.defaultValue ? this.defaultValue : '');
 }
 });
 $('textarea').blur(function(){
 $(this).removeClass("focusField").addClass("idleField");
 if ($.trim(this.value == '')){
 this.value = (this.defaultValue ? this.defaultValue : '');
 }
 });
});

</script>

And add the following code to style.css:


.focusField {
 border:solid 2px #73A6FF;
 background:#EFF5FF;
 color:#000;
 }
.idleField {
 background:#EEE;
 color: #6F6F6F;
 border: solid 2px #DFDFDF;
 }

Now you’ll have styled text-boxes on the form. The .focusfield describes the style of an active text field & .idlefield describes the style of an inactive field.

ADDING THE CHARACTER COUNT & LIMIT

We all know that Twitter has a character limit of 140. Personally, I don’t like the limit but we have to accept the reality! So to make our PHP Application a little realistic we need to add the character count & then limit it to 140. This can easily be done using Javascript. To do so, add the following code snippet to the head of your Index (Index.html) file:


<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#t_update").keyup(function()
{
var box=$(this).val();
var main = box.length *100;
var value= (main / 140);
var count= 140 - box.length;

if(box.length <= 140)
{
$('#count').html(count);
$('#bar').animate(
{
"width": value+'%',
}, 1);
}
else
{
alert('Character Limit Exceeded!');

;
}
return false;
});

});
</script>

You might have noticed in the code above that whenever the character limit of 140 is exceeded, you’ll see a message box saying “Character Limit Exceeded!”:

<pre>{
alert('Character Limit Exceeded!');

;
}

Now add the code below right after “Your Status” and before the status text-box on the HTML form in the Index.html file:


<div align="left" id="character-count"><!--Start Character Count-->
 <div id="count">140</div>
 <div id="barbox"><div id="bar"></div></div>
 </div><!--End Character Count-->

To avoid any confusions on the placement of the above code-snippet in the body of the index.html page, I have pasted the whole code inside the body tag below:


<body>
 <h1><span id="header">Updating Twitter Using PHP</span></h1>

<div id="quote1"><!--Start Quote1-->
<center><p> Learn to send updates to Twitter using its API + PHP! </p></center>
</div><!--End Quote1-->

<div id="form" align="center"><!--Start Form-->
<form name="form1" method="post" action="post-to-twitter.php">
 <p><br />
 <label>
 Twitter Username:
 <input name="t_user" type="text" id="t_user">
 </label>
 </p>

 <p><br />
 <label>Twitter Password:
 <input name="t_pass" type="password" id="t_pass">
 </label>
 </p>

 <p><br />
 <label>Your status:</label>
 </p>
 <p>
 <div align="left" id="character-count">
 <div id="count">140</div>
 <div id="barbox"><div id="bar"></div></div>
 </div>
 </p>
 <br />
 <p>
 <textarea name="t_update" cols="50" rows="5" id="t_update" ></textarea>

 </p>

 <p><br />
 <label>
 <input type="submit" name="Submit" value="Post To Your Twitter Account!">
 </label>
 </p>
</form>
</div><!--End Form-->

<div id="quote2"><!--Start Quote2-->
<center><p>NOTE: We aren't storing your passwords in any way. If you want to try this then go ahead without hesitation!</p></center>
</div><!--End Quote2-->

</body>

Now we’ll style the character-count so add the following code to the style.css file:


#bar
{
background-color:#5fbbde;
width:0px;
height:16px;
}
#barbox
{
float:right;
height:16px;
background-color:#FFFFFF;
width:100px;
border:solid 2px #000;
margin-right:3px;
-webkit-border-radius:5px;-moz-border-radius:5px;
}
#count
{
float:right;
margin-right:8px;
font-family:'Georgia', Times New Roman, Times, serif;
font-size:16px;
font-weight:bold;
color:#666666
}
#contentbox
{
width:450px; height:50px;
border:solid 2px #006699;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}

#character-count {
margin-right:540px;
}

So now we have something like this:

BRINGING LIFE TO OUR APPLICATION WITH PHP

We have almost completed making the script now. All we have to do is to add some code to the post-to-twitter.php file and that’s it! Add the following code to the post-to-twitter.php file:


<?php
$username = ($_POST['t_user']);
$password = ($_POST['t_pass']);
$message = ($_POST['t_update']);

$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)) {
 echo "<p align=\"center\" >".'Sorry, due to an error your Twitter status could not be updated! Please check your username/password!'."</p>";
} else {
 echo "<p align=\"center\">".'Your Twitter status has successfully been updated!'."</p>";
}
?>

You might have noticed the way we are passing the values entered in the text boxes to this PHP script. We had assigned id’s to the textboxes in our HTML script. We are now just importing the values entered in the text boxes with those id’s and assigning them a variable:


$username = ($_POST['t_user']);
 $password = ($_POST['t_pass']);
 $message = ($_POST['t_update']);

And then we just contact Twitter through the following code:


$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");

Now we firstly login the user with the username & password provided and then update the user’s status time-line with the status message entered in the Status box. Finally we display the confirmation message:

if (empty($buffer)) {
<pre> echo "<p align=\"center\" >".'Sorry, due to an error your Twitter status could not be updated! Please check your username/password!'."</p>";
} else {
 echo "<p align=\"center\">".'Your Twitter status has successfully been updated!'."</p>";
}

Now to style our output a little bit we just attach a stylesheet to the script and add a Back button to it. So here is our final code in the post-to-twitter.php file:


<html>
<head>
<title>Twitter-Post Confirmation</title>
<link href="css/style-php.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$username = ($_POST['t_user']);
$password = ($_POST['t_pass']);
$message = ($_POST['t_update']);

$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)) {
 echo "<p align=\"center\" >".'Sorry, due to an error your Twitter status could not be updated! Please check your username/password!'."</p>";
} else {
 echo "<p align=\"center\">".'Your Twitter status has successfully been updated!'."</p>";
}
?>
<div id="history"><!--Start History-->
<a href="javascript:history.back()">Back to the previous page</a>
</div><!--End History-->
</body>
</html>

The stylesheet for this php file is named “style-php.css” and includes the following code:


@charset "utf-8";
/* CSS Document */

body {
 font-size:24px;
 vertical-align:middle;
 text-align:center;
 text-decoration:underline;
 margin-top: 150px;
 }

That’s it! We have successfully made our PHP script using which we can update our Twitter account’s remotely. There are numerous things you can do with the above application. You may use it onto your next project related to twitter or integrate this to your blog to directly post updates of new posts to Twitter without even using external services like Twitterfeed or FeedBurner or any other plugins!

If you have any questions, comments or concerns then feel free to leave a comment :)

<form
name=”form1″ method=”post” action=”post-to-twitter.php”>
<p><br />
<label>
Twitter Username:
<input name=”t_user” type=”text” id=”t_user”>
</label>
</p><p><br />
<label>Twitter Password:
<input name=”t_pass” type=”password” id=”t_pass”>
</label>
</p>

<p><br />
<label>Your status:</label>
</p>
<p>
<div align=”left” id=”character-count”>
<div id=”count”>140</div>
<div id=”barbox”><div id=”bar”></div></div>
</div>
</p>
<br />
<p>
<textarea name=”t_update” cols=”50″ rows=”5″ id=”t_update” ></textarea>

</p>

<p><br />
<label>
<input type=”submit” name=”Submit” value=”Post To Your Twitter Account!”>
</label>
</p>
</form>
</div><!–End Form–>

<div id=”quote2″><!–Start Quote2–>
<center><p>NOTE: We aren’t storing your passwords in any way. If you want to try this then go ahead without hesitation!</p></center>
</div><!–End Quote2–>

</body>
</html>

<script type=”text/javascript” src=”http://jqueryjs.googlecode.com/files/jquery-1.3.js”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘input[type="text"]‘).addClass(“idleField”);
$(‘input[type="text"]‘).focus(function(){
$(this).removeClass(“idleField”).addClass(“focusField”);
if (this.value == this.defaultValue){
this.value = ”;
}
if(this.value != this.defaultValue){
this.select();
}
});
$(‘input[type="password"]‘).addClass(“idleField”);
$(‘input[type="password"]‘).focus(function(){
$(this).removeClass(“idleField”).addClass(“focusField”);
if (this.value == this.defaultValue){
this.value = ”;
}
if(this.value != this.defaultValue){
this.select();
}
});
$(‘textarea’).addClass(“idleField”);
$(‘textarea’).focus(function(){
$(this).removeClass(“idleField”).addClass(“focusField”);
if (this.value == this.defaultValue){
this.value = ”;
}
if(this.value != this.defaultValue){
this.select();
}
});
$(‘input[type="text"]‘).blur(function(){
$(this).removeClass(“focusField”).addClass(“idleField”);
if ($.trim(this.value == ”)){
this.value = (this.defaultValue ? this.defaultValue : ”);
}
});
$(‘input[type="password"]‘).blur(function(){
$(this).removeClass(“focusField”).addClass(“idleField”);
if ($.trim(this.value == ”)){
this.value = (this.defaultValue ? this.defaultValue : ”);
}
});
$(‘textarea’).blur(function(){
$(this).removeClass(“focusField”).addClass(“idleField”);
if ($.trim(this.value == ”)){
this.value = (this.defaultValue ? this.defaultValue : ”);
}
});
});</script>

4 Written ArticlesWebsiteGoogle+

Blog: TutorialsWalk Twitter: @abhishekwebin

39 Comments Best Comments First
  • @Xarem

    Thursday, May 20th, 2010 16:19

    5

    Hi

    Like Matt Rogowski said:
    On June 30, 2010 (5 weeks and 6 days from now), the @twitterapi team will be shutting off basic authentication on the Twitter API

    Take a look:

    So your script just run til 30 of june

    +1
  • Manik Das

    Saturday, April 23rd, 2011 15:46

    35

    The example is not working , I don’t know why

    +1
  • Rupanjan

    Tuesday, June 21st, 2011 16:45

    36

    The above example is not working, anyone can help

    +1
  • nishant

    Wednesday, April 11th, 2012 05:50

    39

    code not update status dude.

    +1
  • Ryan Fitton

    Sunday, May 30th, 2010 13:50

    13

    Any word on using oAuth with this tutorial?
    Great work though :) many thanks, Ryan.

    0
    • Abhishek

      Sunday, May 30th, 2010 19:33

      14

      Making one. Will be up on 1stwebdesigner soon! :)

      0
  • Ilham Maulana

    Monday, June 7th, 2010 19:05

    15

    Nice… But I’ve got a question… It’s a example, “3 minutes ago via API”… How I can change the API word with my website name or application?

    0
  • Al

    Saturday, May 29th, 2010 16:56

    11

    Nice tut!
    Would be great if you made a tutorial using OAuth too! :)

    0
    • Abhishek

      Sunday, May 30th, 2010 00:56

      12

      Making one now!

      0
  • Aan

    Tuesday, June 22nd, 2010 03:31

    17

    it’s cool! thanks for share.. i don’t like waste the time to continued logins.

    0
    • saravanan

      Friday, June 25th, 2010 13:15

      18

      how to replay for the user twit in twitter?

      0
      • Abhishek

        Tuesday, June 29th, 2010 02:35

        19

        What? Can you please clarify your question?

        0
  • ohmohm

    Sunday, May 23rd, 2010 11:30

    9

    Are there some good examples for Oauth Twitter? Especially, easily to migrate from basic authentication.

    0
  • Jordan Walker

    Monday, May 24th, 2010 15:15

    10

    That is a great utility to post to Twitter.

    0
  • Matt Rogowski

    Thursday, May 20th, 2010 13:28

    3

    Although it’s a very good tutorial, it’s largely irrelevant as Twitter is shutting down this method in favour of OAuth soon.

    0
    • Anon

      Thursday, May 20th, 2010 16:30

      1

      only a couple of weeks left of the old authentication

      0
  • Cosmin Negoita

    Thursday, May 20th, 2010 13:03

    2

    A very good tutorial. I always wanted to make my own Twitter application because I could design it the way I want…Thank you!

    0
  • santhos

    Thursday, May 20th, 2010 13:41

    4

    I’ve just been exploring the Twitter API this morning. You wrote a very nice tutorial! And indeed, the Twitter API is very easy to use!!

    0
  • Abhishek

    Friday, May 21st, 2010 07:53

    6

    I agree that Twitter will abandon this method but I will update this post with the “OAuth” usage soon ( will add that as a second method to this).

    0
  • Matt Harper

    Sunday, May 23rd, 2010 02:14

    8

    I had been trying to do this for the past several days but finally found a tutorial on the topic..thanks :)

    0
  • Rahul

    Friday, May 21st, 2010 12:09

    7

    awesome article !! good tutorial :) will try it

    0
  • Babar Shahzad Chaudary

    Wednesday, June 30th, 2010 12:05

    20

    OAuth authentication postponed until August 16th 2010.

    0
    • Abhishek

      Tuesday, July 6th, 2010 22:08

      22

      Wow, they are shutting it down on my Birthday!! lol ;)

      0
  • Endy

    Sunday, October 17th, 2010 15:42

    31

    this method is now dead. and i was using something very similar on one of my sites now i have to rewrite it :(

    0
  • Rahul

    Friday, October 15th, 2010 11:14

    30

    The code you have provided in the article is not working. It always gives me the 401 error. I think so twitter has blocked this method. Can you please help me how can I do the same thing i.e. auto tweets on twitter.

    Hope you will reply me on that.

    0
  • Abhishek

    Tuesday, October 19th, 2010 07:58

    32

    Hello everyone,
    This method has been terminated by Twitter now. There’s another API method in place and you can Read more about that here:
    http://www.1stwebdesigner.com/tutorials/twitter-app-oauth-php/
    Thanks.

    0
  • Stefano

    Friday, February 11th, 2011 11:13

    33

    Hi, can you help me??
    I don’t able to connect with twitter with this script in
    The example does not work too.

    thanks

    0
    • Ryan

      Sunday, March 6th, 2011 18:38

      34

      This type of authorization is no longer supported by Twitter. You need to look at OAuth.

      0
  • Tiz

    Friday, December 30th, 2011 20:16

    38

    The scritp works BUT it doesn’t post anything.
    It tells that i’ts posted. I check the timeline on Twitter and I don’t fidn what I post.
    When I enable the applciation to work on my acount, Twitter gives me back a PIN number that I have not clue where to put
    Could you halp me please?

    0
  • Carlos

    Thursday, November 17th, 2011 22:27

    37

    hi,
    Is it possible to add an auto DM, when someone is following us?

    0
  • nasir

    Sunday, October 3rd, 2010 10:20

    29

    hi this code is not working any more now can anyone tell me what happend.

    0
  • Jaiswar Vipin

    Monday, September 27th, 2010 16:01

    28

    This this not working any more. Now you have to use new twitter api integrated wuth OAuth.

    0
  • Abhishek

    Monday, July 5th, 2010 23:10

    21

    As of today, this method is still working ;) lol…..Twitter forgot to shut this down..:P

    0
  • pywen

    Sunday, July 25th, 2010 07:02

    23

    hi i do have an error with the codes.
    it has an error on this “$curl_handle = curl_init();”
    and it says
    Fatal error: Call to undefined function curl_init() .
    so what does this mean?
    can anyone help me ? thanks a lot .

    Regards, pywen

    0
  • Kai

    Saturday, September 18th, 2010 18:44

    26

    Hi
    I really appreciate what you are doing for the community. I have a uestion : I just tested your code for using with twitter oauth. Workds great. But the only thing is that I always have to hit the button “Allow” on Twitters site? Is tehre a way to automate that?

    Can I still use this code on this page to update twitter or won’t this work as of the September 2010 changes?
    Thanks

    0
  • Krishna

    Wednesday, September 22nd, 2010 09:33

    27

    $twitter_api_url = “http://twitter.com/statuses/update.xml”;
    $twitter_data = “status=hi guys”;
    $twitter_user = “username”;
    $twitter_password = “password”;
    $ch = curl_init($twitter_api_url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, “{$twitter_user}:{$twitter_password}”);
    $twitter_data = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    //print_r($httpcode);
    if ($httpcode != 200) {
    echo “Don’t Panic! Something went wrong, and the tweet wasn’t posted correctly.”;
    }
    else
    {
    echo ‘Congrats it is succesfully posted’;
    }
    hi any one help me. I have used the above code for posting a message in twitter but it is not posting. It is returning $httpcode as 401. Please help me.

    0
  • Francesco Goffredo

    Thursday, September 2nd, 2010 11:31

    25

    Hi, thanks for tutorial.

    1) I try the script on my blog
    2) I try your demo.

    on both sites can not post anything on twitter
    can be a problem of my account?

    0
  • Abhishek

    Wednesday, August 25th, 2010 11:02

    24
    -2
  • nishant

    Wednesday, April 11th, 2012 05:50

    39

    code not update status dude.

    +1
  • Tiz

    Friday, December 30th, 2011 20:16

    38

    The scritp works BUT it doesn’t post anything.
    It tells that i’ts posted. I check the timeline on Twitter and I don’t fidn what I post.
    When I enable the applciation to work on my acount, Twitter gives me back a PIN number that I have not clue where to put
    Could you halp me please?

    0
  • Carlos

    Thursday, November 17th, 2011 22:27

    37

    hi,
    Is it possible to add an auto DM, when someone is following us?

    0
  • Rupanjan

    Tuesday, June 21st, 2011 16:45

    36

    The above example is not working, anyone can help

    +1
  • Manik Das

    Saturday, April 23rd, 2011 15:46

    35

    The example is not working , I don’t know why

    +1
  • Stefano

    Friday, February 11th, 2011 11:13

    33

    Hi, can you help me??
    I don’t able to connect with twitter with this script in
    The example does not work too.

    thanks

    0
    • Ryan

      Sunday, March 6th, 2011 18:38

      34

      This type of authorization is no longer supported by Twitter. You need to look at OAuth.

      0
  • Abhishek

    Tuesday, October 19th, 2010 07:58

    32

    Hello everyone,
    This method has been terminated by Twitter now. There’s another API method in place and you can Read more about that here:
    http://www.1stwebdesigner.com/tutorials/twitter-app-oauth-php/
    Thanks.

    0
  • Endy

    Sunday, October 17th, 2010 15:42

    31

    this method is now dead. and i was using something very similar on one of my sites now i have to rewrite it :(

    0
  • Rahul

    Friday, October 15th, 2010 11:14

    30

    The code you have provided in the article is not working. It always gives me the 401 error. I think so twitter has blocked this method. Can you please help me how can I do the same thing i.e. auto tweets on twitter.

    Hope you will reply me on that.

    0
  • nasir

    Sunday, October 3rd, 2010 10:20

    29

    hi this code is not working any more now can anyone tell me what happend.

    0
  • Jaiswar Vipin

    Monday, September 27th, 2010 16:01

    28

    This this not working any more. Now you have to use new twitter api integrated wuth OAuth.

    0
  • Krishna

    Wednesday, September 22nd, 2010 09:33

    27

    $twitter_api_url = “http://twitter.com/statuses/update.xml”;
    $twitter_data = “status=hi guys”;
    $twitter_user = “username”;
    $twitter_password = “password”;
    $ch = curl_init($twitter_api_url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, “{$twitter_user}:{$twitter_password}”);
    $twitter_data = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    //print_r($httpcode);
    if ($httpcode != 200) {
    echo “Don’t Panic! Something went wrong, and the tweet wasn’t posted correctly.”;
    }
    else
    {
    echo ‘Congrats it is succesfully posted’;
    }
    hi any one help me. I have used the above code for posting a message in twitter but it is not posting. It is returning $httpcode as 401. Please help me.

    0
  • Kai

    Saturday, September 18th, 2010 18:44

    26

    Hi
    I really appreciate what you are doing for the community. I have a uestion : I just tested your code for using with twitter oauth. Workds great. But the only thing is that I always have to hit the button “Allow” on Twitters site? Is tehre a way to automate that?

    Can I still use this code on this page to update twitter or won’t this work as of the September 2010 changes?
    Thanks

    0
  • Francesco Goffredo

    Thursday, September 2nd, 2010 11:31

    25

    Hi, thanks for tutorial.

    1) I try the script on my blog
    2) I try your demo.

    on both sites can not post anything on twitter
    can be a problem of my account?

    0
  • Abhishek

    Wednesday, August 25th, 2010 11:02

    24
    -2
  • pywen

    Sunday, July 25th, 2010 07:02

    23

    hi i do have an error with the codes.
    it has an error on this “$curl_handle = curl_init();”
    and it says
    Fatal error: Call to undefined function curl_init() .
    so what does this mean?
    can anyone help me ? thanks a lot .

    Regards, pywen

    0
  • Abhishek

    Monday, July 5th, 2010 23:10

    21

    As of today, this method is still working ;) lol…..Twitter forgot to shut this down..:P

    0
  • Babar Shahzad Chaudary

    Wednesday, June 30th, 2010 12:05

    20

    OAuth authentication postponed until August 16th 2010.

    0
    • Abhishek

      Tuesday, July 6th, 2010 22:08

      22

      Wow, they are shutting it down on my Birthday!! lol ;)

      0
  • Aan

    Tuesday, June 22nd, 2010 03:31

    17

    it’s cool! thanks for share.. i don’t like waste the time to continued logins.

    0
    • saravanan

      Friday, June 25th, 2010 13:15

      18

      how to replay for the user twit in twitter?

      0
      • Abhishek

        Tuesday, June 29th, 2010 02:35

        19

        What? Can you please clarify your question?

        0
  • Ilham Maulana

    Monday, June 7th, 2010 19:05

    15

    Nice… But I’ve got a question… It’s a example, “3 minutes ago via API”… How I can change the API word with my website name or application?

    0
  • Ryan Fitton

    Sunday, May 30th, 2010 13:50

    13

    Any word on using oAuth with this tutorial?
    Great work though :) many thanks, Ryan.

    0
    • Abhishek

      Sunday, May 30th, 2010 19:33

      14

      Making one. Will be up on 1stwebdesigner soon! :)

      0
  • Al

    Saturday, May 29th, 2010 16:56

    11

    Nice tut!
    Would be great if you made a tutorial using OAuth too! :)

    0
    • Abhishek

      Sunday, May 30th, 2010 00:56

      12

      Making one now!

      0
  • Jordan Walker

    Monday, May 24th, 2010 15:15

    10

    That is a great utility to post to Twitter.

    0
  • ohmohm

    Sunday, May 23rd, 2010 11:30

    9

    Are there some good examples for Oauth Twitter? Especially, easily to migrate from basic authentication.

    0
  • Matt Harper

    Sunday, May 23rd, 2010 02:14

    8

    I had been trying to do this for the past several days but finally found a tutorial on the topic..thanks :)

    0
  • Rahul

    Friday, May 21st, 2010 12:09

    7

    awesome article !! good tutorial :) will try it

    0
  • Abhishek

    Friday, May 21st, 2010 07:53

    6

    I agree that Twitter will abandon this method but I will update this post with the “OAuth” usage soon ( will add that as a second method to this).

    0
  • @Xarem

    Thursday, May 20th, 2010 16:19

    5

    Hi

    Like Matt Rogowski said:
    On June 30, 2010 (5 weeks and 6 days from now), the @twitterapi team will be shutting off basic authentication on the Twitter API

    Take a look:

    So your script just run til 30 of june

    +1
  • santhos

    Thursday, May 20th, 2010 13:41

    4

    I’ve just been exploring the Twitter API this morning. You wrote a very nice tutorial! And indeed, the Twitter API is very easy to use!!

    0
  • Matt Rogowski

    Thursday, May 20th, 2010 13:28

    3

    Although it’s a very good tutorial, it’s largely irrelevant as Twitter is shutting down this method in favour of OAuth soon.

    0
    • Anon

      Thursday, May 20th, 2010 16:30

      1

      only a couple of weeks left of the old authentication

      0
  • Cosmin Negoita

    Thursday, May 20th, 2010 13:03

    2

    A very good tutorial. I always wanted to make my own Twitter application because I could design it the way I want…Thank you!

    0

Comments are closed.

54.196.168.236 - unknown - unknown - US