Ted pottel
Ted pottel

Reputation: 6983

Trying to write a script to get my twitter timeline, cannot get return information

I’m trying to write a twitter program to get my tinme line. I’m using Abraham Williams authentication code. I cannot figure out how to pharse the return value. I think it is return a stdClass, which I’m confused about how it works. I can display the objects values by print_r. I was able to see what the xml and json return values would be at http://dev.twitter.com/doc/get/statuses/home_timeline.

code

// 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('mykey', 'secret key', $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);
// how do i get the information out of home_timeline

Upvotes: 0

Views: 665

Answers (1)

abraham
abraham

Reputation: 47833

GET statues/home_timeline returns an array of statues. You can either access them directly like $home_timeline[0]->text or write a foreach loop.

foreach ($home_timeline as $status) {
  echo "Tweet: $status->text<br />\n";
}

Upvotes: 1

Related Questions