created_at returns Jan 1st 1970. How can I get it to return correct tweet timestamp?


#1

I’m using get statuses/user_timeline to display $tweets as $tweet

created_at is returning Jan 1st 1970 instead of the actual tweet time

Any idea why?

Thanks!


#2

Here’s my code, minus keys/secrets

//LATEST TWEET FUNCTION
function latest_tweet(){
global $post;
require_once(“js/vendor/twitteroauth/twitteroauth.php”);
$consumer_key = ‘’;
$consumer_secret = ‘’;
$access_token = ‘’;
$access_token_secret = ‘’;
$nb_of_tweets = 1;
$include_rts = false;
$date_format = ‘g:i A M jS Y’;
$connection = new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret);
$twitter_user_id = ‘rightsource’;
$tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitter_user_id."&count=".$nb_of_tweets."&include_rts=”.$include_rts);

foreach ($tweets as $tweet){ 
    //links
    $tweet = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target='_blank' href=\"\\0\">\\0</a>",  $tweet->text); 
    //#
    $tweet = preg_replace('/(^|\s)#(\w*[a-zA-Z_]+\w*)/', '\1<a target="_blank" href="https://twitter.com/search?q=%23\2&src=hash">#\2</a>', $tweet);
    //@
    $tweet = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a target="_blank" href="http://twitter.com/$1" target="_blank">@$1</a>', $tweet );
    // Convert Tweet display time to a UNIX timestamp. Twitter timestamps are in UTC/GMT time.
	$tweet_time = strtotime($tweet->created_at);    
	$display_time = date($date_format,$tweet_time);

     
    echo $tweet;
    
    ?> <div class="twitter-details" ><?php echo $display_time ?></div> <?php 

}

}