Anonymous Anonymous - 2 months ago
132 0

No description

PHP

TwitterAPI Example

<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "720689202388680704-p6FJ5nPjY541bRQ1jgxbdBKpBmPErGK",
    'oauth_access_token_secret' => "gkEI6O5U6Hgw2UAsVqmTvvue1ePj2DSrL51nFypX3QdkR",
    'consumer_key' => "5eksjF9yEXMmb545DNmK23o2v",
    'consumer_secret' => "mrtfUgvRW4hTUKXeue5LET7bTD7sn2puxXzJYDEHUDq7HdOAm1"
);
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$requestMethod = "GET";
if (isset($_GET['user']))  {$user = $_GET['user'];}  else {$user  = "reecepeel_";}
if (isset($_GET['count'])) {$count = $_GET['count'];} else {$count = 4;}
$getfield = "?screen_name=$user&count=$count";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest(),$assoc = TRUE);
if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();}
foreach($string as $items)
{
    echo "Time and Date of Tweet: ".$items['created_at']."<br />";
    echo "Tweet: ". $items['text']."<br />";
    echo "Tweeted by: ". $items['user']['name']."<br />";
    echo "Screen name: ". $items['user']['screen_name']."<br />";
//    echo "Followers: ". $items['user']['followers_count']."<br />";
//    echo "Friends: ". $items['user']['friends_count']."<br />";
    echo "<hr />";
}
?>
Comments