Reputation: 57
I'm trying to get the home feed on twitter with twitter oauth api. I tried with this code and first it worked. But now it just gives me a blank page. But my big question is how I can get the text and date and everything important. This is my code:
EDIT: I got the code working, but I still wonder how I can get the text from each post the array.
<?php
session_start();
require_once('twitter/twitteroauth.php');
require_once('twitter/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');
/* Some example calls */
//$connection->get('users/show', array('screen_name' => 'alexastely'));
$feed = $connection->get('statuses/home_timeline');
//echo $feed;
print_r($feed);
//$connection->post('statuses/destroy', array('id' => 5437877770));
//$connection->post('friendships/create', array('id' => 9436992));
//$connection->post('friendships/destroy', array('id' => 9436992));
?>
Upvotes: 0
Views: 365
Reputation: 476
Is that what you mean?
$feed = $connection->get('statuses/home_timeline');
foreach($feed as $post) {
echo $post['text'];
echo $post['created_at'];
}
You can read more about tweet object here - https://dev.twitter.com/docs/platform-objects/tweets
Edit:
$feed = $connection->get('statuses/home_timeline');
foreach($feed as $post) {
echo $post->text;
echo $post->created_at;
}
Upvotes: 1