Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend OAuth with twitter single access tokens

I'm developing an application where it requires users to sign in using twitter and OAuth. Everything works just fine thanks to Zend_OAuth. The problem is that the web app will also make some calls to the twitter API but these will be handled internally without the need of authenticating. Twitter Dev provides an 'access_token' and 'access_token_secret' keys for this purpose (Mentioned here http://dev.twitter.com/pages/oauth_single_token )

The problem is that I can't get Zend_OAuth to play nice with existing access tokens. Is there anyone who can help with a few lines of code how can I make an API call with my existing keys without being redirected to Twitter's Authorize page ? I know it can be done.

PS. If possible, I don't want to use external libraries like the ones mentioned in dev.twitter.com - just what Zend Framework is offering

Thanks!

like image 378
remedix Avatar asked Nov 29 '22 18:11

remedix


1 Answers

With ZF version 1.10.8 minimal code required to post on Twitter is:

$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
'oauth_token' => 'REPLACE_WITH_TOKEN',
'oauth_token_secret' => 'REPLACE_WITH_TOKEN_SECRET'
));

$twitter = new Zend_Service_Twitter(array(
'consumerKey' => 'REPLACE_WITH_CONSUMER_KEY', 
'consumerSecret' => 'REPLACE_WITH_CONSUMER_SECRET',
'accessToken' => $token
));

$response = $twitter->status->update('REPLACE WITH MESSAGE');

All tokens and secrets can be accessed after registering your application on http://dev.twitter.com

like image 95
forcecode Avatar answered Dec 04 '22 05:12

forcecode