Archive

Posts Tagged ‘Twitter API’

Free Java Twitter API – Twitter4J and OAuth

March 25th, 2010

The previous Twitter4J post only introduces the basic authentication and sending a simple tweet to your twitter account.

As I wasn’t really good with OAuth, it took me quite some time to understand how Twitter and OAuth worked as the Twitter’s OAuth wiki didn’t really helped me.

Luckily there’s Twitter4J. However, the OAuthUpdate class doesn’t work just like that.
The good thing is the class is a good starting point to understand the OAuth flow of events.

Basically this post would help me to remember the flow in the future, and hopefully is useful for you if you’re trying to integrate with Twitter using OAuth. (Twitter states that they plan to deprecate basic authentication by June 2010.)

This is only meant for reference purposes, please change the code below as needed for your own purpose. It is not meant as a working OAuth code, but merely for your understanding.

Prerequisite
Since we’re creating an app to integrate with Twitter, you are required to register the app with Twitter.
Register your app at : http://twitter.com/oauth_clients

Customize the Twitter4J settings in Configuration class

defaultProperty.setProperty(“twitter4j.source”, “MarvinAPI”);
defaultProperty.setProperty(“twitter4j.clientURL”, “your_url”);
defaultProperty.setProperty(“twitter4j.http.userAgent”, “MarvinAPI http://marvinlee.net/blog/”);
defaultProperty.setProperty(“twitter4j.oauth.consumerKey”,”your_key”);
defaultProperty.setProperty(“twitter4j.oauth.consumerSecret”,”your_secret”);

1) Get Request Token
To kickstart OAuth, your application need to send a request to Twitter, to obtain a “request” token.
Notice that you are not required to use user’s actual user name and password anywhere here.

Twitter twitter = new Twitter();
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println(“Request token: “+ requestToken.getToken());
System.out.println(“Request token secret: “+ requestToken.getTokenSecret());

Keep the requestToken.

2) User authorize your application
After the request, your app should direct the user to Twitter’s authorization page, where if the user will then grant permission to your app to send tweets or updates on his/her behalf.
Append the requestToken from 1) using this URL : http://twitter.com/oauth/authorize?oauth_token=<strong><requestToken.getToken()></strong>

If your application is created with a Call back URL, then Twitter will redirects the user to the Call back URL you created and your app should store the Access Token returned.

If you do not have a Call back URL, then the Access Token or OAuth Verifier will be displayed.

3) Get Access Token
The significant of this is to keep the OAuth verifier as this will then verify with Twitter that your app is now successfully recognized with the following request.

Make the following request from your app, now with the tokens returned from 1) and the OAuthVerifier from 2).

Twitter twitter = new Twitter();
twitter.getOAuthAccessToken(requestToken, requestTokenSecret, oauthVerifier);
System.out.println(“Access Token:” + accessToken.getToken());
System.out.println(“Access Token Secret:” + accessToken.getTokenSecret());

This request will then return an Access Token.
Now, these Access Token and Access Token Secret is IMPORTANT for your app.
This is the user password for your application that updates Twitter.
You now have in-hand, the temporary password for the user that Twitter has granted your application to use in replace of the actual password.

4) Store the token and token_secret
What else do you need to do now? Store the Access Token and Secret of course!
You wouldn’t want to go through steps 1) and 3) every time your apps try to send a tweet on behalf of the user.
accessToken.getToken(), accessToken.getTokenSecret() values should be within your application or datastore.

5) Subsequent Update with OAuth
Any subsequent tweets that your application send using the user account will only need to use the Access Token.

Twitter twitter = new Twitter();
AccessToken accessToken = new AccessToken(“token”,”token_secret”);
twitter.setOAuthAccessToken(accessToken);
twitter.updateStatus(“Check out the source of this tweet status!”);

The cool thing is, you have the advantage of showing a customized URL (tweet source) on all tweets sent using this approach!

Have fun. :-)

Java, Open Source, Software , , ,

Free Java Twitter API – Download Twitter4J

March 22nd, 2010

Many websites or applications are now integrating with Twitter following the popular usage of Twitter as the new age social media.

We see many twitter clients and for those who wanted to build their own Twitter clients or apps that integrate with the twitter API in Java, Twitter4J is the solution.

Twitter4J is a 100% Java API and a open source solution.
Source code is available for download and the API that you can use is very straightforward and easy.

Examples:

Simple Update

Twitter twitter = new Twitter(username, password);
Status status = twitter.updateStatus(“This is a test update tweet”);

The basic integration will require the credentials information, that is the username and password.
This is called basic authentication.

Twitter actually uses OAuth as well, a protocol that allows applications to integrate with it with software keys instead of users’ username and password.
Unless you are building Twitter applications or clients solely for your own use, you should seriously consider using OAuth API.

Java, Open Source, Review, Software , , ,

Best Technology Products of 2009

December 29th, 2009

The year of 2009 is coming to a close and the following is my personal listing of the best in 2009 (for technology).

1. Twitter & Twitter API

twitter_growth
Twitter has grown exponentially throughout the world and fast becoming the top Web 2.0 application.
Sometimes it’s not the most complicated application that wins, and Twitter that only takes 140 chars for a tweet/status update wins it.

twitter_growth1
Notice that it has become almost the top 100 websites of every country (except China where access to it has been blocked).

twitter_api
Twitter API has enabled a huge number of client applications and business grow with Twitter through the API usage and having an API to integrate with social networks is fast becoming a mandatory feature.

2. HTC and Android
While the world was immensed with the iPhone frenzy prior to 2009, other phone manufacturers are busy capturing the mobile market by having secret and not-so-secret projects like the Palm Pre and Google Android.

HTC is now ranked the fourth largest smartphone maker, after Nokia, Research In Motion (BlackBerrys) and Apple. HTC’s Android portfolio now includes the original G1 and MyTouch on T-Mobile, the Hero on Sprint, and the Tattoo and Droid Eris on Verizon and has at least five other Android phones planned for 2010.
That does not even include the HTC Nexus One, aka the Googlephone, is among the most anticipated devices of 2010.
HTC and Android walked side by side in 2009 and is definitely something we could watch out for in 2010.

3. MovieBox Media Players

I have no idea what is the right name for these products, it came with MovieBox, Media Players, etc that could play Real Player formats and various other internet downloadable movies.

clamul_moviebox

It easily gain following by movie buffs due to its convenience of playing digital movie files directly to the television.

This device stands between your tv and a USB 2.0 compatible device (like external HDD or USB thumbdrive that has any image files or movie files). It can then play the content that are compatible to your TV, even make slideshows for photos as well.
I foresee its much cheaper to have a home theater or home cinema now as compared to a few years ago.

4. GPS with Internet on the phone, roam the world

With GPS you can roam the world and with GPS on your phone with mobile internet access, there is no place that you cannot venture too (of course except to location where there is no mobile data signal).

nav-gallery-25

GPS has enabled human to accurately position a location and to easily make a first time travel to a place they have never been to before.
Add it with more information surrounding the location (like more landmarks and F&B attractions nearby) and by providing directions, it has now became easier for anyone to travel around the world.

5. Point and shoot cameras with DSLR capabilities
Should you buy a DSLR or Point and Shoot Digital Camera?
In 2009, you can have both.

olympus-pen-e-p1
Olympus came out with the Olympus PEN E-P1 is a hybrid 12.3-megapixel interchangeable lens camera that manages to merge the look, feel and flexibility of a traditional film SLR with the convenience of a slim, lightweight digital point-and-shoot camera.
The price is still steep but we are sure to see more professional looking photos in the making anyday, and I bet video too..

So there you have, my personal best technology products in 2009.

What is your best technology product or services you encountered in 2009? Please leave your comment below.

Internet, Technology , , , , , , , , ,