Created
July 7, 2014 16:09
-
-
Save tszym/09691f7046912fe5ec7a to your computer and use it in GitHub Desktop.
Twitter API - Tweet data
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
<!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 tweet 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 tweet infos in PHP</h2> | |
<p>This page is a basic showcase of the way to retrieve infos about a message (tweet). 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> & | |
<a href='http://wiki.github.com/abraham/twitteroauth/documentation'>Documentation</a> | | |
Contact @<a href='http://twitter.com/abraham'>abraham</a> | |
</p> | |
<hr /> | |
<h2>A tweet</h2> | |
<p> | |
Author: | |
<img src="<?php echo $tweet->user->profile_image_url_https; ?>" | |
alt="<?php echo $tweet->user->url; ?>" /> | |
<?php echo $tweet->user->name, ' @', $tweet->user->screen_name, '<br>';?> | |
<span style="font-size: 20px;"><?php echo $tweet->text; ?></span><br> | |
<img src="<?php echo $tweet->entities->media[0]->media_url_https; ?>" | |
alt="<?pph echo $tweet->entities->media[0]->display_url; ?>" /><br> | |
Retweets: <?php echo $tweet->retweet_count; ?> Favorites: <?php echo $tweet->favorite_count; ?> | |
</p> | |
<hr /> | |
<?php if (isset($menu)) { | |
echo $menu; | |
} ?> | |
</div> | |
<?php if (isset($status_text)) { | |
echo '<h3>'.$status_text.'</h3>'; | |
} ?> | |
</body> | |
</html> |
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 | |
/** | |
* @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 */ | |
$tweet = $connection->get('statuses/show', array('id' => '479004865046523904')); | |
/* Include HTML to display on the page | |
* Thiw is where we use the response | |
*/ | |
include('template.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment