I'm using this php library for interacting with twitter api called tmhOAuth https://github.com/themattharris/tmhOAuth and I'm having trouble getting a permanent user access token and token secret. I think the one's that I'm currently getting lasts only for the current browser tab. In the code below I'm assigning the user token and user secret to a session.
function access_token($tmhOAuth) {
$tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
$tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
//store user token and secret to a session to be accessed on a different page
$_SESSION['u_token'] = $tmhOAuth->config['user_token'];
$_SESSION['u_secret'] = $tmhOAuth->config['user_secret'];
$code = $tmhOAuth->request(
'POST',
$tmhOAuth->url('oauth/access_token', ''),
array(
'oauth_verifier' => $_REQUEST['oauth_verifier']
)
);
if ($code == 200) {
$_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
unset($_SESSION['oauth']);
header('Location: ' . tmhUtilities::php_self());
} else {
outputError($tmhOAuth);
}
}
Then I just access the user token and secret from another page:
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'xxx',
'consumer_secret' => 'xxx',
$_SESSION['u_token'],
$_SESSION['u_secret']
));
$tweet = 'tweet';
$code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
'status' => $tweet
));
echo json_encode($code); //I always get 401 here
?>
The problem is I always get the 401 response.