How to get the latest Twitter status using PHP

In this totorial i will show you how to get latest twitter status using php in Here’s the final code that goes into your website project. Copy your API Keys and replace values below where indicated. You may also like How to get profile data in Twitter using Codeigniter and How to Login with Facebook in CodeIgniter.

PHP Code

<?php
    include_once('twitteroauth/twitteroauth.php');

    $twitter_customer_key = 'Your API Key';
    $twitter_customer_secret = 'Your API Secret';
    $twitter_access_token = 'Your Access Token Key';
    $twitter_access_token_secret = 'Your Access Token Secret';

    $connection = new TwitterOAuth($twitter_customer_key, $twitter_customer_secret, $twitter_access_token, $twitter_access_token_secret);

    $my_tweets = $connection->get('statuses/user_timeline', array('screen_name' => 'Your Name', 'count' => 1));

    echo '<div class="twitter-bubble">';

    if (isset($my_tweets->errors)) {
        echo 'Error :' . $my_tweets->errors[0]->code . ' - ' . $my_tweets->errors[0]->message;
    } else {
        echo $my_tweets[0]->text;
    }
    echo '</div>';

?>

Leave a Reply

Your email address will not be published. Required fields are marked *