Archive for March, 2010

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.

Since we’re creating an app to integrate with Twitter, you are required to register the app with Twitter.
Register your app at :

Customize the Twitter4J settings in Configuration class

defaultProperty.setProperty(“twitter4j.source”, “MarvinAPI”);
defaultProperty.setProperty(“twitter4j.clientURL”, “your_url”);
defaultProperty.setProperty(“twitter4j.http.userAgent”, “MarvinAPI”);

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 :<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.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.


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 , , ,

Blog Advertising with Google Adsense, Google Affliate Network, Amazon Associates

March 18th, 2010

After getting my first bonus from Adsense, I figure maybe I should share about the other blog advertising or monetization approaches that I have used.

Since the revenue isn’t much, I humbly think this is not a show-off, and if it goes well maybe I could consider putting this into my annual blog review as well.

Google Adsense

For a starter, Google Adsense is the best choice, as within moments you sign up and put the code on your site or blog, it will start serving ads.
However, the click rate and payment that you can get is considered low (at least for me).
Considering it’s for Google and SEO, either related or not, I’m still keeping Adsense. 🙂

Google Affliate

I have only started signing up Google Affiliate Network and testing it on this blog not long ago. The ad impressions served had exceeded 22k, but the earnings is nil.
I’m considering removing them altogether, as it is not easy to have readers clicking the ads, being brought to a page where they will purchase something and then only I get paid.
Considering with Google Adsense that it take so much traffic to get little revenue, Google Affiliate would need higher traffic to get better conversions.

Amazon Associates

Just like Google Affiliates, Amazon Associates is a referral network or affiliate program where you only get commission when the product advertised are purchased by someone.
Only because I have used Amazon Associates way earlier, I got USD 2 from one sale so far.
I’m still wondering how far it can go to reach the payment threshold.


Nuffnang is also one that I have contemplated joining for a long while before taking it up the start of this year.
Two months and with two campaigns went by and RM 0.50 in the account with RM 49.50 to go before payout with a RM 1 charges.
What do you think?


Innity is one that I have heard or read of many nice reviews that it has a high pay rate.
Unfortunately, I am not even qualified to join it yet.
I guess that’s how they are able to pay a lot, as the publishers are sure to be getting a lot of traffic to view their advertisements.


Kontera is a In Text advertising provider and you get paid when links created dynamically are clicked.
I have only joined Kontera not very long ago and it seems that their pay rate is good, probably can go against Adsense.


Adbrite is one contextual advertising method, just like Adsense. As I have only just signed up and there isn’t enough to display, I can’t say much about Adbrite at the moment.

Now you see that I’m not getting much from these advertisers, it’s not that they don’t work, it’s only that I’m not making them work for me, or I can say I do not know how to make them work effectively.
I can see that many have made handsomely from these advertisers.
I’ll continue to monitor, tweak and improve.

What about you? What is the best advertising programs you have used and worked best for you?

PS: One thing you have to take note is that I am not doing paid post. 🙂

blogging, Internet Marketing , , , , , ,