Last active
August 29, 2015 14:01
-
-
Save rischanlab/555fa49074f5e5650d41 to your computer and use it in GitHub Desktop.
Get twitter Bio using Twitter API Exchange [PHP]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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