• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Get Twitter account information based on username

Here is a function that uses Twitter API, to get information about Twitter account based on Twitter username.

If there is no account with that username, an error will be returned, if Twitter account is protected - empty array will be returned, else array with user information and latest account activities will be returned. Use print_r to see structure of array and all possible information.


function twitter_info($username)
    //forming url
    $url = "".$username.".json?count=1";
    //curl request
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlData = curl_exec($curl);
    //decoding json structure into array
    return current(json_decode($curlData, true));

$twitter_username = "trianapark";
$arr = twitter_info($twitter_username);
echo "<p>Twitter status for ".$twitter_username.": ".$arr['text']."</p>"

You may also be interested in:

Powered by

blog comments powered by Disqus