Single User Zend_Service_Twitter
Note: This article was originally published at Planet PHP on 2 October 2010.Zend Framework, you might want to show the Twitter messages to your audience.
Although the Zend Framework manual extensively describes how to set up a true Twitter application with the new OAuth implementation of Twitter using Zend_Service_Twitter and Zend_Oauth (since ZF-1.10.0), this is not what you're looking for. You need a simple approach, using the single user OAuth implementation of Twitter.
Registration at Twitter.
Register your "app" to twitter at http://dev.twitter.com/apps/new where you'll be presented a registration form for your app. Since it's not really an app, you should register your website as the app.
Once registered, you need to accept the general terms for usage of the Twitter API.
Once accepted, your applications registered and you can start implementing it. But for a single user approach, you need to retrieve your access tokens.
Now it's time to fetch those tweets and post them on your website.
Since these tokens are config elements, we store them in our application.ini as we keep this as our main configuration file for our whole website.
; Twitter serviceservice.twitter.oauth.username = "DragonBe"
service.twitter.oauth.oauth_token = "1234567-xPhPanDz3nDfRam3W0RkN0wW1THS1nGl3Z3nd0aUth"
service.twitter.oauth.oauth_token_secret = "8tH1sStr1nGmUstB3sT0r3ds0MwH3r3V3RryS3cr3t"
Now a simple model can be used to set up the verification process and retrieve the Twitter instance.
AAA protected $_config;AAA
AAA protected $_twitter;
AAA public function __construct()
AAAAAAA $config = new Zend_Config_Ini(
AAAAAAAAAAA APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
AAAAAAA $this-_config = $config-service-twitter-oauth;
AAAAAAA $this-_twitter = new Zend_Service_Twitter();
Truncated by Planet PHP, read more at the original (another 4375 bytes)