Skip to content

Instantly share code, notes, and snippets.

@rischanlab
Last active August 29, 2015 14:01
Show Gist options
  • Save rischanlab/555fa49074f5e5650d41 to your computer and use it in GitHub Desktop.
Save rischanlab/555fa49074f5e5650d41 to your computer and use it in GitHub Desktop.
Get twitter Bio using Twitter API Exchange [PHP]
<?php
/** Just simple code to get twitter Account Bio **/
/** Rischan Mafrur **/
/** April 28 2014 **/
ini_set('display_errors', true);
// set display error
function getBio ($screenName){
include 'constants.php'; // constants.php contains access token, token secret, consumerkey, and consumer secret
#require_once('Cache.php');
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => $accessToken,
'oauth_access_token_secret' => $accessTokenSecret,
'consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret
);
$apiUrl = "https://api.twitter.com/1.1/users/show.json"; //twitter API 1.1
$requestMethod = 'GET';
$getField = '?screen_name=' . $screenName;
$twitter = new TwitterAPIExchange($settings); //dont forget to clone TwitterAPIExchange
$response = $twitter->setGetfield($getField)
->buildOauth($apiUrl, $requestMethod)
->performRequest();
$data = json_decode($response);
$screen_name = $data->screen_name;
$followers = $data->followers_count;
$friends = $data->friends_count;
$protected = $data->protected;
if ($protected==false) {
$p = "false";
} else {
$p = "true";
}
$created_at = $data->created_at;
$favourites_count = $data->favourites_count;
$listed_count = $data->listed_count;
$time_zone = $data->time_zone;
$statuses_count = $data->statuses_count;
$location = $data->location;
$bio = array(
"name" => $screen_name,
"followers" => $followers,
"friends" => $friends,
"protected" => $p,
"created_at" => $created_at,
"favourites_count" => $favourites_count,
"listed" => $listed_count,
"status" => $statuses_count,
"location" => $location,
"time_zone" =>$time_zone
);
return $bio;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment