Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




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.

<?php

function twitter_info($username)
{
    //forming url
    $url = "http://twitter.com/statuses/user_timeline/".$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);
    curl_close($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 BlogAlike.com

blog comments powered by Disqus