I created a program to show the twitter timeline of the last 40 tweets. When I have it show my time line, it worked fine. When I created a new for my customer, the time line diod not match up with his time line.
This is what I did: 1. Created a app in my account. Use the Consumer key and Consumer secret for myb prgtam.
Got a accessToken and $accessTokenSecret by 1. Going to my account 2. Run a ascrip I called register 3. Used the return code to run a scrip I call validate.
It all works fine. I repeat the above procedure using my clints account to get a new accesstoken and acesstokensecret.
The program worked, but the time line does not match up with my clients. register.php
<?php
require_once('twitteroauth/twitteroauth.php');
$oauth = new TwitterOAuth(xxxxxxxxxx','xxxxxxxxxxxxxxxxxxxxxxxxx');
$request = $oauth->getRequestToken();
$requestToken = $request['oauth_token'];
$requestTokenSecret = $request['oauth_token_secret'];
// place the generated request token/secret into local files
file_put_contents('request_token', $requestToken);
file_put_contents('request_token_secret', $requestTokenSecret);
// display Twitter generated registration URL
$registerURL = $oauth->getAuthorizeURL($request);
echo '<a href="' . $r开发者_如何学PythonegisterURL . '">Register with Twitter</a>';
?>
validate
<?php
// Retrieve our previously generated request token & secret
$requestToken = file_get_contents("request_token");
$requestTokenSecret = file_get_contents("request_token_secret");
// Include class file & create object passing request token/secret also
require_once("twitteroauth/twitteroauth.php");
$oauth = new TwitterOAuth('xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxx', $requestToken, $requestTokenSecret);
// Generate access token by providing PIN for Twitter
$request = $oauth->getAccessToken(NULL, $_GET["2300291"]);
$accessToken = $request['oauth_token'];
$accessTokenSecret = $request['oauth_token_secret'];
// Save our access token/secret
print("saving tokens from twitter </br>");
print "token=".$accessToken;
file_put_contents("access_token", $accessToken);
file_put_contents("access_token_secret", $accessTokenSecret);
?>
display the time line
<?php
// Read in our saved access token/secret
$accessToken = file_get_contents("access_token");
$accessTokenSecret = file_get_contents("access_token_secret");
// Create our twitter API object
require_once("twitteroauth/twitteroauth.php");
$oauth = new TwitterOAuth('xxxxxxxx', 'xxxxxxxx', $accessToken, $accessTokenSecret);
// Send an API request to verify credentials
$credentials = $oauth->get("account/verify_credentials");
//echo "Connected as @" . $credentials->screen_name;
// Post our new "hello world" status
$home_timeline = $oauth->get('statuses/home_timeline',array('count' => 40));
// print_r($home_timeline);
// top of table
echo " <table width=\"200\" border=\"0\" align=\"center\"> ";
foreach ($home_timeline as $status)
{
// new item table
echo "<tr>";
echo "<td>";
echo "<img src=\"".$status->user->profile_image_url."\"";
echo "</td>";
echo "<td>";
echo $status->text;
echo "</td>";
echo "</tr>";
// space
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo"</td>";
echo "</tr>";
// break;
// echo "image:". $status->user->profile_image_url."<br>"."<br>";
}
// end of table
echo "</table>";
精彩评论