Skip to content

Instantly share code, notes, and snippets.

@tszym
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tszym/dc8c57f08217be2d7013 to your computer and use it in GitHub Desktop.
Save tszym/dc8c57f08217be2d7013 to your computer and use it in GitHub Desktop.
Twitter API - Account data
<?php
/**
* @file
* User has successfully authenticated with Twitter. Access tokens saved to session and DB.
*/
/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
/* If method is set change API call made. Test is called by default. */
//$content = $connection->get('account/verify_credentials');
/* The calls */
$content = $connection->get('users/show', array('screen_name' => 'BunkrApp'));
/* Include HTML to display on the page
* Thiw is where we use the response
*/
include('template.php');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Twitter - Get account infos in PHP</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
img {border-width: 0}
* {font-family:'Lucida Grande', sans-serif;}
</style>
</head>
<body>
<div>
<h2>Twitter - Get account infos in PHP</h2>
<p>This page is a basic showcase of the way to retrieve infos about an account. If you are having issues try <a href='./clearsessions.php'>clearing your session</a>.</p>
<p>
Links about the lib author:
<a href='http://github.com/abraham/twitteroauth'>Source Code</a> &amp;
<a href='http://wiki.github.com/abraham/twitteroauth/documentation'>Documentation</a> |
Contact @<a href='http://twitter.com/abraham'>abraham</a>
</p>
<hr />
<?php echo 'Account ', $content->name; ?>
<img src="<?php echo $content->profile_image_url_https ;?>" alt="<?php echo $content->name;?>" /><br>
You can contact to @<?php echo $content->screen_name;?> <br>
<p>
<?php echo $content->followers_count, ' followers<br>';
echo $content->friends_count, ' friends (following)<br>';
echo 'Has ', $content->favourites_count, ' favorite tweets<br>';
echo 'Published ', $content->statuses_count, ' tweets<br>';
?>
</p>
<hr />
<?php
if (isset($menu)) {
echo $menu;
} ?>
</div>
<?php
if (isset($status_text)) {
echo '<h3>'.$status_text.'</h3>';
} ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment