November 8, 2012 11:00 am

Login with Twitter OAuth in PHP V 1.1 Updated

Today I have worked on Twitter oAuth and faced many problems how to get access token for offline access to my application etc. In this tutorial I will show you how to authorize application and add tweets, remove tweets, follow friend and unfollow friend.

Twitter oAuth V 1.1 Updated.

The script contains two folders called oauth and images with PHP files.


– OAuth.php // Twitter OAUTH library


callback.php //Call back page create permanent credentials

config.php // Configuration

connect.php // Check application credentials

destroysessions.php // Erase all old sessions // html design view

index.php // Main index file show data

redirect.php // Redirect to twitter for authorization

Create App on twitter click here

PHP Code

Edit config.php


Shows a button for twitter authorization if not authorized.

Redirect you to redirect.php generate temporary credentials oauth access token and oauth token secret

Authorize on twitter and return on callback.php and get permanent credentials oauth access token and oauth token secret you can save them in database and update status any time you want.


When you authorize application it will return temporary credentials oauth access token, oauth token secret and a oauth verifier with verifier you will get new oauth access token and oauth token secret with this method.

Now you will be able to get

User credentials

Show user Information

Post new tweet

Delete tweet

Follow a friend

Unfollow a friend


Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • Karan Banerjee

    this doesn’t gets email id of the twitter user like facebook. how can we get twitter users email id?

    • Huzoor Bux

      The user’s email address can not be retrieved via the API. This is a deliberate design decision by the API team.

  • srinuchilukuri

    Hi Sir ,
    Nice Article
    im using and tweet with text content working fine how to tweet with image
    plz replay me…

    Thanks in advance

    • huzoorbux

      Thanks @srinuchilukuri:disqus there will be an update soon.

  • rasez

    when i click on sign in button this error show:
    Could not connect to Twitter. Refresh the page or try again later.

  • ashish

    when i click on sign in button this error show:
    Could not connect to Twitter. Refresh the page or try again late

    same problem like rasez
    please help me to solve it

    • Mac Senour

      Assuming you’ve not solved this…

      Check your keys, public and secret. I had this issue and found that there was an added space at the end of my codes. I removed this space, and poof, no issues. Check also the error code with an “echo”. I did and found the error was 401, no access given.

      Hope that helps,

  • Amrendra Singh

    Helped me in my issue for fetching user data. Thanks 🙂

  • How can i see name – email with session .. this is with array .. I dont wanna array I wanna name – email bla bla bla

  • I cannot download the source code even I have subscribed

  • Mac Senour

    I have this on my site but there is a single issue. When a returning user loads my site, attempts to login, he is asked if he wants to authorize the app again. This is confusing since he already authorized it a few days prior on his last visit.

    What procedure do you suggest that pulls the authorization from DB and let’s Twitter know the user is signed in.

    Basically, once he is authorized, he needs to only login the next time not re-authorize. Your example doesn’t do that.



    • huzoorbux

      Twitter gives this screen again and again not remember users access like Facebook I have tried it many times but no luck if you find some way please share with us.

      • Mac Senour

        I’m still looking, but I think the hint is given here:

        “Authorize on twitter and return on callback.php and get permanent credentials oauth access token and oauth token secret you can save them in database and update status any time you want.”


  • Joshua Sedore

    Help! It won’t let me download! I have subscribed but it doesnt seem to recognize my email and therefore wont let me download the script!

  • Paresh

    Do i require to have read/write permissions to get account/verify_credentials?

  • Ӊello mates, nice piece of writing ɑnd fastidious urging commented at tҺіs plaсe, I am genuinely enjoying Ьy theѕе.

  • dev_ronak

    the result set is in array format.
    i want to display the same in string format ex. Username or screen_name etc…
    can u pls help…

  • Jainendra Pal

    Undefined index: oauth_token in C:wampwwwliveoauthtwitteroauth.php on line 80