{"errors":[{"code":89,"message":"Invalid or expired token."}]}

php

#1

I am using code

<?php
    function buildBaseString($baseURI, $method, $params) {
    $r = array();
    ksort($params);
    foreach($params as $key=>$value){
        $r[] = "$key=" . rawurlencode($value);
    }
    return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}

function buildAuthorizationHeader($oauth) {
    $r = 'Authorization: OAuth ';
    $values = array();
    foreach($oauth as $key=>$value)
        $values[] = "$key=\"" . rawurlencode($value) . "\"";
    $r .= implode(', ', $values);
    return $r;
}

function returnTweet(){
    $oauth_access_token = "7xxxxxw3";
    $oauth_access_token_secret = "Zxxxxx1VO";
    $consumer_key = "a4xxxxxbCf";
    $consumer_secret = "KrxxxxgWB";
    $twitter_timeline = "user_timeline";  
	//  mentions_timeline / user_timeline / home_timeline / retweets_of_me
$hash = hash_hmac('md5','The quick brown fox jumped over the lazy dog.', '	KxxxxSegWB');
    //  create request
        $request = array('screen_name' => 'vivekcyber', 'count' => '3');
 $oauth = array(
        'oauth_consumer_key'        => 'a4HxxxxxxbCf',
        'oauth_nonce'               => time(),
        'oauth_signature_method'    => 'HMAC-SHA1',
        'oauth_token'               => '7xxxxxYBw3',
        'oauth_timestamp'           => time(),
        'oauth_version'             => '1.0'
    );

    //  merge request and oauth to one array
        $oauth = array_merge($oauth, $request);

    //  do some magic
 $base_info = buildBaseString("https://api.twitter.com/1.1/statuses/$twitter_timeline.json", 'GET', $oauth);
  $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
        $oauth_signature = base64_encode($hash);
        $oauth['oauth_signature'] = $oauth_signature;

    //  make request
        $header = array(buildAuthorizationHeader($oauth), 'Expect:');
        $options = array( CURLOPT_HTTPHEADER => $header,CURLOPT_HEADER => false,
        CURLOPT_URL => "https://api.twitter.com/1.1/statuses/$twitter_timeline.json?". http_build_query($request),  CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); $feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
return $json;
}

$tweet = returnTweet();
echo $tweet;

?>

#2

I think you would be better off using a proven twitter oauth tool like this one https://github.com/abraham/twitteroauth
It is good piece of software and is well documented too