Accesing oAuth without autentication screen (this could be done?)


Hi there again,

I have a question, it is possible to gain automatic access to my account without human intervention? I mean, I’m still working on this app and the idea is to launch the script by a Linux Cronjob.

So this is the process (or at least the idea) I have many accounts I the script starts, select the keys stored in data base, then I select the content from data base too and in a cycle the tweets are sent.

This is what I want to do and I don’t know if it’s possible. I still don’t have a session variable, “access_token”.

I hope that I have been explicit enough, but in any case, ask me anything that you want about this. Please Help ME! :’(

Thank you so very much! - H


Hi @Heiroon,

What you’re wanting to do is persist access tokens for an extended period of time – instead of storing access token and access token secret in a session, you could do so in a configuration file or within a database (depending on how public the distribution of these keys are anyway – you wouldn’t publicly distribute a software package containing other user’s access tokens).

You’ll need to either build a web flow to obtain the other access tokens and store them or use another tool that allows you to accomplish the same.


Ok, thanks!

Now I got the idea. But how I could do that? may you give me some directions? Please?? u_u

I’m kinda lost…


Fine, I got it until the part where you said that I have to “build a web flow to obtain the access tokens”.

I had stored all the other tokens in my data base. I’m trying to connect by this way, but it returns me error 401 (unauthorized).

I’m doing it like this:

$tweet_text = date('Y-m-d h:i:s'); print "Posting...\n"; $result = post_tweet($tweet_text); print "Response code: " . $result . "\n";
	function post_tweet($tweet_text) {
		  // Use Matt Harris' OAuth library to make the connection
		  // This lives at:
		  $connection = new tmhOAuth(array(
		    'consumer_key' => '4vxpunKdUhaWEnL2cmm8nQ',
		    'consumer_secret' => 'xxxx',
		    'user_token' => '333675948-cqF9Ivqj6f4Yhy6VLOp4SZeTZIxjk0Mqida8AK0j',
		    'user_secret' => 'xxxx',
		  // Make the API call
		    array('status' => $tweet_text));
		  return $connection->response['code'];


You’ll want to regenerate your API keys and secrets now – you shouldn’t post them to a public forum. I’ll get back to you on helping debug this.


It was not mine… That keys come with the example code… :slight_smile: But Thanks for the advice… Ok I’ll wait… Thank you again!


By the way, I am using this method and it works, but it make the connection with the sessions and like that is useless for me…

define('CONSUMER_KEY', 'xxxxxxxxxxxxx');
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxx')
define('OAUTH_CALLBACK', 'http://webserver2/~hpartidas/twitter_new/prueba_api/callback.php');

if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret']))
		$twitter_content='<div class="tweet_login">
							<a href="redirect.php"><img src="images/lighter.png" alt="Sign in with Twitter"/></a>
		echo $twitter_content;
		$access_token = $_SESSION['access_token'];

		$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

		$content = $connection->get('account/verify_credentials');
		$connection->post('statuses/update', array('status' => "Test"));					


I am Logging into the twitter account using Oauth.I have also a logout button in my ios app.After successfully logging into my twitter .i want to log in as a new user in twitter by this logout button. i used the same code for login .but it is not working .Please help me