Abhishek

I am Abhishek Bhardwaj, a 16 year old and love to sit in front of my computer. I write on my blogs @ TutorialsWalk & APIGuides. . You may want to talk to me on Twitter.

40 responses to “Creating a Simple Twitter App using oAuth and PHP”

  1. robbie

    Hello … just to give my gratitude at first when i saw this tutorial … i passed it up because it looked very technical …but as the hours passed and the frustration kicked in i came back across … and its brillant exactly what i have been looking for….. BUT of course always a but…. when i follow all the instructions and upload the files i get this parse error ….

    Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’

    … on line 4 of the EpiCurl.php file ….HELP i checked the Phpinfo of my site i have curl enabled and it is quite a late version . Any help would be super appreciated

  2. Marcus

    Thanx for this great tutorial!!!
    I´ve been looking for a long time for a code like this!

  3. Twitter API mit OAuth - Webmeister Blog

    [...] Creating a Simple Twitter App using oAuth and PHP [...]

  4. Francesco

    thank you thank you thank you thank you thank you thank you thank you

  5. Creating a Simple Twitter App using oAuth and PHP « HUONG PHO's Blog

    [...] print? [...]

  6. debonairemaN

    dont use localhost in your callback URL, Just replace that PORTION of the address with 127.0.0.1

    e.g.

    http://127.0.0.1/blah/blah/bleh.php

  7. Mark

    Thanks to you and Jaisan for all the great articles on the Twitter API…
    I seem to missing something, it seems that I can only access twitter by starting from scratch and fails the tokens on repeated access, part of which you may have touched on above about token lives. My question would be is it possible to create an application that can be called as a stand-alone and update my Twitter account without repeating the Twitter authorization each time? (Application would create the new tweets). Would the application have to use basic (curl) login to Twitter prior to creating the access tokens?

  8. bharath

    Thank You i was searching for this in many places you teached me very easily
    Thanks ………..

  9. cheza

    Hi,

    just out of curiosity. How do you verify a user, once you have all the needed tokens, if he revisits your page. Clearly you’d have to – somehow – identify that visitor als the one specific user.

    Actually, in my opinion, at that point you won’t get around asking for twitter screen name and password, which you will have to compare to other screen names and pws which will have to be stored in your DB. => All bonuses of oauth are gone by then… I am currently stuck at that point in developing a twitter app.

    It would be nice if you could point me in the right direction! (even though I am developing with RoR instead of PHP :)!)

    thanks cheza

  10. freak

    It doesn’t generate a oauth_token for me, I have edited the secret.php but it doesn’t work. I’m using a .in domain from securesignup.net, site is hosted on 0fees.net.

  11. neko

    hello.
    your tutorial so easily to understand!
    thank you so mach.

    but i have a problem.
    i try to tweet in japanese,status is incorrect.
    In english , status is OK.

    i think encode problem.
    how can i solve ?
    please help me.

    1. Neko

      I solve that.
      I try to make original script,so I can tweet in multibyte(japanese).
      thank you!

  12. Rims

    Hello… i have used the same code in my php project bcz i want to run it on localhost.
    I have also registered application in twitter and changed the secret.php file. but then also i m getting error….
    Call to undefined function curl_multi_init() in C:\Program Files\xampp\htdocs\twitter\lib\EpiCurl.php on line 21.

    Plz tell me how to resolve this error.
    I have searched about it there is no prob with PHP installed bcz it is giving information when i call function phpinfo();.

    1. Abhishek

      The problem is that you do not have cURL extension installed (or it is disabled).
      Reconfigure it and it should work!

  13. seddik

    this tutorial helped me really much but just one thing i didn’t understand, for the callback url, I tried http://localhost/twitter/index.php but at twitter application settings it doesn’t accept this url ?

    1. Abhishek Bhardwaj

      lol Sorry, I think Twitter doesn’t accept any URL which doesn’t have a .com or .net or all those other domain suffixes.

  14. drooh

    I dont understand, everytime I have to click to sign in authenticate with twitter? It would be nice to just do that once and not have to do it every time you wanted to post to twitter.

    1. Abhishek Bhardwaj

      That’s because I am not storing the token keys anywhere. This is just a simple app! Maybe in the future, I’ll have another tutorial on 1WD that connects to a database and stores the authentication keys so that the user doesn’t have to login again and again!!

      1. Jim

        It would be awesome if you could add it to this tutorial any time soon.
        Thank you very much

    2. Francesco

      Hi drooh,
      I have your same problem.
      have you solved?

      tnx

  15. yankymetro

    I don’t know what’s the callback URL. It’s hard. Explain it to me better. Thanks.

    1. Abhishek

      Do you really think its hard? Check the first screenshot and that’s your answer otherwise the callback URL is: http://your-website.com/“”index.php”" ……..

  16. SG

    Great post!

    Can you also tell us how to test it locally? I want to develop and test an app locally before uploading it. What should be the web / callback URL for this and how should localhost / server handle it?

    Thanks a lot.

    1. Abhishek

      The localhost server should handle it normally & your callback URL should be http://localhost/twitter/index.php

  17. Jordan Walker

    Wow, excellent tutorial with very detailed instruction.

  18. Zachary Collins

    Hey there,
    Great tutorial! Only problem I am having is when I connect my account and it brings me back to the index.php page, I refresh, and it doesnt load the user.

    Thanks,
    Zachary Collins

    1. Abhishek

      Check your callback URL on Twitter, and did you change the API Keys in secret.php file?

      1. Carter Thayer

        I checked both, the refresh problem is still happening. Let me know if you find a solution. Also, same thing is happening on your demo page.

  19. Rvarm1

    Hi! I was making a similiar application, but whenever I clicked sign in with twitter, it gave me this error:
    “Woah there!
    This page is no longer valid. It looks like someone already used the token information you provided. Please return to the site that sent you to this page and try again … it was probably an honest mistake.”

    Can you please help me? I already tried resetting the keys, but it didnt work.

    Thanks for your help!

  20. Jaisen Mathai

    I added this article to the readme of the Twitter-Async library on Github.

    http://github.com/jmathai/twitter-async

    Thanks for the write up.

  21. Box Model Junkie

    It nice to see that it’s relatively easy to integrate oAuth into your app.

    1. Abhishek

      Yes, It initially looks difficult but its relatively easy once you dive into the code.

  22. Siddharth

    hey thats wonder tutorial..
    am actually using these.. and could u say..
    in case i we want to use these if the user s not online.. but registered..
    how to get and store the oauth token and secrets ?
    and how to ue them again to update the satus ?/
    can u help me out ?
    am tryin to do for http://sms2twitter.in

    1. Abhishek

      That can be done using a database which stores all tokens! I also emailed you from your website so I guess we should continue our conversation there :D

  23. ditatompel

    Nice tutorial! Thank you for sharing! =)

    1. Abhishek

      Thank you!! :)

  24. Irina

    Great tutorial! Thanks. I just wanted to make a similar app :)

    1. Abhishek

      Glad you liked it :)

Leave a Reply