tags:

views:

87

answers:

2

Hi,

I want to show my latest tweet in a web page. My tweets are private for some reason and I should login to Twitter. I know that the basic HTTP authentication was deprecated in August 2010. How can I provide authentication in my PHP code to fetch private tweets (or userTimeline if I'm not mistaken)?

I've searched but unfortunately didn't find anything useful! :( Thanks in advance for your help!

A: 

Authentication to Twitter is done via OAuth. A pretty simple way to access your Twitter account with PHP is using the latest version of ZendFramework. It will be required to register your app on twitter, which allows you to generate an oauth token. This token can be used to access your private twitter feed.

See documentation of Zend_Service_Twitter and Zend_Oauth_Consumer. Here http://framework.zend.com/manual/en/zend.oauth.introduction.html you will find a pretty good introduction of using Zend OAuth together with twitter (note that the address used in the $config array has to be api.twitter.com/oauth and NOT twitter.com/oauth )

However, you can also make your Tweets public in your twitter account settings (Settings -> Account -> Tweet Privacy -> Uncheck "Protect my tweets"). Then your tweets will be available on the public timeline (not at once, you may have to wait a bit).

Hope that helps! -Jan

Jan Wy
+1  A: 

Jan, I heard about ZendFramework while I was searching for the answer but It's complicated for me.

I found the solution here that illustrates how I can use OAuth based on Abraham’s Twitter OAuth library (http://tinyurl.com/catd64).

The key note is that I stored my 'oauth_access_token' in a database or somewhere else immediately after first login via my twitter credential. Then I remove the code which allow users to login to twitter and reuse stored credential to fetch the latest tweet by using $user->status->text variable.

It's a geeky job. It maybe has some potential security flaws but I'm not sure! ;)

By the way, Thanks a lot for your reply, Jan! :D

cartoonist