Twitter API V1.1 Development

Recently Twitter have changed their API to access the their feeds from your Site. In previous version 1.0 there is no restriction to get the feed and display to your website .
Now in current version V1.1 to fetch the feed you need Access Token from twitter so in current API V1.1 Authentication required.
To access the json feed ,you need access token from Twitter , you can go through The developer tutorials from twitter for this .
To get Twitter Access Token you need to create your own customer key and secret key from Twitter developer Account and those keys need to pass to twitter token authentication url  that will return the access token in a return variable access_token.

You can use the below function to get Access Token :


function get_tweets_token()

// Function to get Access Token

$c_key = ‘YOUR KEY’;

$c_secret = ‘YOUR SECRET KEY’;

$auth = base64_encode( $c_key . ‘:’ . $c_secret );

$opt = array(        ‘http’ => array(            ‘method’ => ‘POST’,

‘header’ => ‘Authorization:  Basic ‘.$auth,

‘content’ => ‘grant_type=client_credentials’        )    );

$text = stream_context_create($opt);

$result = json_decode( file_get_contents(‘twitter token authentication url’, false, $text) );

$tkn = array(              ‘consumer_key’      => $c_key,

‘access_token’      => $result->access_token             );

return $tkn;



To get Twitter Json Feed in your web site  , You can use below code


$tkn = get_tweets_token();
$opt = array(‘http’ => array(
‘method’ => ‘GET’,
‘header’ => ‘Authorization: Bearer ‘.$tkn[‘access_token’]
$url=’TWITTER API URL ?screen_name=TWITTER USER NAME &count=COUNT;
$text = stream_context_create($opt);
$data = json_decode( file_get_contents( $url, false, $text) );
//Loop With data and show feed


Hope this post will help you to develop your Own Display to Twitter Feed .

If you have anything regarding this post  add a comment or contact .



Show Buttons
Hide Buttons