November 8, 2012 11:00 am

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

- OAuth.php // Twitter OAUTH library

images

callback.php //Call back page create permanent credentials

config.php // Configuration

connect.php // Check application credentials

destroysessions.php // Erase all old sessions

html.inc // 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

Index.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.

Summery

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

 


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,
      Mac

  • Amrendra Singh

    Helped me in my issue for fetching user data. Thanks :)

  • http://senocak.tk/ Anl Şenocak

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

  • http://webernizer.com/ Ari Susanto

    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.

    Suggestions?

    Mac

    • 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.”

        Mac

  • 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!