Twitter时间线与正确的时间线不匹配。使用twitters api

时间:2011-06-27 21:30:54

标签: php api twitter

我创建了一个程序来显示最近40条推文的推特时间线。当我显示我的时间线时,它工作正常。当我为我的客户创建一个新的时间时,时间线diod与他的时间线不匹配。

这就是我所做的: 1.在我的帐户中创建了一个应用程序。使用Consumer键和Consumer myb prgtam的秘密。

获得了accessToken和$ accessTokenSecret     1.转到我的帐户     2.运行一个名为register的ascrip     3.使用返回代码运行我称之为验证的脚本。

一切正常。 我使用我的clints帐户重复上述过程以获得一个新的accesstoken和acesstokensecret。

该计划有效,但时间线与我的客户不符。 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="' . $registerURL . '">Register with Twitter</a>';
?>

验证

<?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);
?>

显示时间线

<?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>";

0 个答案:

没有答案