How to automatically update Twitter status by PHP


I was wondering how to update my status automatically in twitter using PHP, & found some interesting articles on the internet. I found One all-in-one open-source php project which needed CURL support, but many servers can restrict that access to curl. So with a little help from here & the official Twitter API, I’ve just prepared a working script to Update your Status at twitter automatically 🙂 The best thing is, you don’t need to have CURL enabled! (it will then use fsockopen if CURL is disabled)

Download Code

http://hostcode.sourceforge.net/view/53

How to Use

Once downloaded, save the code in a file like twitter.php

Then use following simple function to automatically update your status:

require_once("twitter.php");
$username = "YOUR-TWITTER-USERNAME";
$password = "YOUR-TWITTER-PASSWORD";
$status = "My First status from the API!";
// encode the status
$status = urlencode($status);
// Tweet it!
$twitter = tweet($username,$password,$status);
// Now you can do additional fun with the data returned at $twitter variable. That's not necessary after all

Troubles? Let me know…… Got help? Cheer me up!

Advertisements

18 thoughts on “How to automatically update Twitter status by PHP

  1. Thank you, thank you! I’ve been looking for this code for months now, as all the existing scripts seem to mysteriously stop working sometime in April.
    The urlencode is tricky: it didn’t work for me and the tweets were unreadable. However, if you substitute line 6 for
    $status=str_replace(” “, ‘+’, $status);
    it works perfectly.
    Thank you again!

    1. Thanks a lot for your comment, it would help others to troubleshoot their problem. However, urlencode did work for me!

    1. once you download, rename the file like twitter.php. Then create a new page, which you will use to update your status. First include this line:

      require_once(“twitter.php”);

      Then put your status message in $status variable. For example:

      $status = “Feeling lonely!”;

      Next put your twitter username in $username variable & password in $password variable.

      $username = “YOUR-TWITTER-USERNAME”;
      $password = “YOUR-TWITTER-PASSWORD”;

      Next, put these codes & u’re done 🙂

      $status = urlencode($status);
      $twitter = tweet($username,$password,$status);

      1. like where do i do this at on the site, “Then create a new page, which you will use to update your status. First include this line:

        require_once(“twitter.php”);”

  2. @paulmicken, I’ve tried my best to explain… you should have very basic of PHP files to use this script 😦

    You should put all your scripts in a .php “page” and at the beginning of it, write

    require_once(“twitter.php”);

    Then write rest of the codes shown above.

    Save the file & run it to update your message in twitter.

    ——————

  3. This is fantastic! Thank-you!

    What would be great, is if the response had some easy to retrieve variables like which method was successful, the twitter response, etc. I know they’re all there but it requires some digging around in the response and json decoding to find it all.

    All in all though, great script!

  4. Thank you very very much bdhacker…
    It’s great to having this code.
    Keep hacking… 🙂

  5. Hmm, I am puzzled. I am receiving no errors, but this script just simply doesn’t work. Any troubleshooting suggestions?

  6. hey..i just did the above steps..there were no errors shown..but the tweet isn’t seen(its not been posted to my twitter)..plz help me out

  7. Hey!
    I tried the code. it didnt show anything. then i echoed $twitter and got the following err:
    {“errors”:[{“code”:53,”message”:”Basic authentication is not supported”}]}

    what might be i m doing wrong. i have rechecked the username and password many times.

    thanks in advance for the help

  8. help me pls!
    I tried the code. it didnt show anything. then i echoed $twitter and got the following err:
    {“errors”:[{“code”:53,”message”:”Basic authentication is not supported”}]}

    what might be i m doing wrong. i have rechecked the username and password many times.

    thanks in advance for the help

Comments are closed.