Single User OAuth using Zend Framework’s Twitter Service Class

3 Comments

Michelangelo van Dam wrote a neat little article to help with single user Twitter access.  What that means is that you can set up a Twitter application and then start tweeting without having to use a username and password.  Michelangelo did it in the context of a Zend Framework MVC application and so this blog post is only about doing what he did using the Twitter service as a library instead of the whole kit ‘n kiboodle.  Basically, here’s your code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$config = array(
  'username' => 'kpschrade',
  'consumerKey' => 'CONSUMER_KEY',
  'consumerSecret' => 'CONSUMER_SECRET',
  Zend_Oauth_Token_Access::TOKEN_PARAM_KEY => 'TOKEN',
  Zend_Oauth_Token_Access::TOKEN_SECRET_PARAM_KEY => 'SECRET'
);
$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken($config[Zend_Oauth_Token_Access::TOKEN_PARAM_KEY]);
$accessToken->setTokenSecret($config[Zend_Oauth_Token_Access::TOKEN_SECRET_PARAM_KEY]);
$twitter = new Zend_Service_Twitter();
$twitter->setLocalHttpClient($accessToken->getHttpClient($config));
 
$result = $twitter->account->verifyCredentials();
 
if (isset($result->screen_name)) {
echo 'verified';
} else {
echo 'not verified';
}

3 thoughts on “Single User OAuth using Zend Framework’s Twitter Service Class

    1. [email protected]… did I seriously???  Van Dammit, is what I meant.  Will change

Leave a Reply

Your email address will not be published. Required fields are marked *