<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pakzilla &#187; Twitter4J</title>
	<atom:link href="http://www.pakzilla.com/tag/twitter4j/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pakzilla.com</link>
	<description>A blog on Programming, Web and Technology</description>
	<lastBuildDate>Tue, 31 Aug 2010 10:06:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use and retain Twitter4J OAuth access token</title>
		<link>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/</link>
		<comments>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 20:41:34 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=831</guid>
		<description><![CDATA[
			
				
			
		
I  was stuck in a problem that how to re use access token, once user has authenticated by Twitter (on call back URL). I got it working. There was problem in my understanding about request token vs access token. When user first time comes on call backed URL. I take request token and token secret [...]


Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/' rel='bookmark' title='Permanent Link: How to avoid DeadlineExceededException in Google App Engine'>How to avoid DeadlineExceededException in Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/' rel='bookmark' title='Permanent Link: How to register an app with Twitter'>How to register an app with Twitter</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.pakzilla.com%2F2010%2F03%2F01%2Fhow-to-use-and-retain-twitter4j-oauth-access-token%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.pakzilla.com%2F2010%2F03%2F01%2Fhow-to-use-and-retain-twitter4j-oauth-access-token%2F&amp;source=tahirakram&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I  was stuck in a problem that how to re use access token, once user has authenticated by Twitter (on call back URL). I got it working. There was problem in my understanding about request token vs access token. When user first time comes on call backed URL. I take request token and token secret from session and prepare the access token. Here the place where I was confused.</p>
<p>Now if user presses the refresh button or you want to get user information again from twitter any where in your application. You need to use the access token and this method<strong> twitter.setOAuthAccessToken(String1, String2)</strong>. Because user has already been authenticated by Twitter. You can save this information in session.</p>
<pre class="brush: java;">
HttpSession session = request.getSession();

twitter.setOAuthConsumer(Constants.CONSUMER_KEY,Constants.CONSUMER_SECRET);

if (session.getAttribute(&quot;aToken&quot;) == null){
	// request token
	String token = (String) session.getAttribute(&quot;token&quot;);
	String tokenSecret = (String)session.getAttribute(&quot;tokenSecret&quot;);
	AccessToken accessToken =
		twitter.getOAuthAccessToken(token, tokenSecret);
	twitter.setOAuthAccessToken(accessToken);

	// save the access token, that are different from request token
	session.setAttribute(&quot;aToken&quot;, accessToken.getToken());
	session.setAttribute(&quot;aTokenSecret&quot;, accessToken.getTokenSecret());

}else{
	// use the access token to authenticate user whenever you want
	twitter.setOAuthAccessToken((String)session.getAttribute(&quot;aToken&quot;),
		(String)session.getAttribute(&quot;aTokenSecret&quot;));
}
User user = twitter.verifyCredentials();
</pre>
<p>If you are also developing some app by using Twitter4J API on Google App Engine. Please give feedback on it.</p>
<p><strong>Twitter4J Quick Tutorial:</strong> <a href="http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/">A quick tutorial on how to develop Twitter app by using Twitter4J on Google App Engine</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=How+to+use+and+retain+Twitter4J+OAuth+access+token%3A+http://b2l.me/kpzy3+%28via+%40tahirakram%29+&amp;source=shareaholic" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;t=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;title=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;title=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;title=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;title=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;title=How+to+use+and+retain+Twitter4J+OAuth+access+token" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/&amp;imageurl=" rel="nofollow" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/' rel='bookmark' title='Permanent Link: How to avoid DeadlineExceededException in Google App Engine'>How to avoid DeadlineExceededException in Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/' rel='bookmark' title='Permanent Link: How to register an app with Twitter'>How to register an app with Twitter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to register an app with Twitter</title>
		<link>http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/</link>
		<comments>http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 19:47:51 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=675</guid>
		<description><![CDATA[
			
				
			
		
If you want to develop a Twitter app. You need to register your application with Twitter. That means you should have your production URL ready before you think to start your development. When you finished with registration, you will receive consumer key and consumer secret. These unique credentials will help your app to interact with [...]


Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
<li><a href='http://www.pakzilla.com/2010/04/13/download-gravity-a-symbian-s60-twitter-client/' rel='bookmark' title='Permanent Link: Download Gravity, a Symbian S60 Twitter client'>Download Gravity, a Symbian S60 Twitter client</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F11%2F23%2Fhow-to-register-an-app-with-twitter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F11%2F23%2Fhow-to-register-an-app-with-twitter%2F&amp;source=tahirakram&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you want to develop a Twitter app. You need to register your application with Twitter. That means you should have your production URL ready before you think to start your development. When you finished with registration, you will receive consumer key and consumer secret. These unique credentials will help your app to interact with Twitter. No big deal. You can visit your all registered applications on <a href="http://twitter.com/oauth">http://twitter.com/oauth</a>. And to register for new app you need to visit <a href="http://twitter.com/apps/new">http://twitter.com/apps/new</a><br />
</p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-676" title="registering_new_app_with_twitter" src="http://www.pakzilla.com/wp-content/upload/registering_new_app_with_twitter.png" alt="registering_new_app_with_twitter" width="586" height="539" /></p>
<p></p>
<p style="text-align: left;">Some things need to consider are the call back URL and the access type. Basically call back URL will be the production level URL of your application not your local host. If you want to use Twitter for authentication, then on successful authentication your call back URL will be invoked. Access type is the operations that your app is going to do. Read-only mode is that you only want the read access. And in Read-Write mode you can send tweets and can do other operations.</p>
<p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-678" style="border: 1px solid black;" title="twitter_setting_callback_url" src="http://www.pakzilla.com/wp-content/upload/twitter_setting_callback_url.png" alt="twitter_setting_callback_url" width="474" height="139" /></p>
<p>And I assume that you people know how Twitter authenticates. I am telling here in steps.</p>
<ol>
<li>You app will generate a URL with unique access token</li>
<li>Your visitor will click on that URL, which will take your the Twitter web. Where he could allow your app to access or deny</li>
<li>On if he allows your app, he will be asked to enter his Twitter user name and password</li>
<li>And on successful authentication, Twitter will take user to your web. By calling your mentioned call back URL</li>
</ol>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=How+to+register+an+app+with+Twitter%3A+http://b2l.me/krd5f+%28via+%40tahirakram%29+&amp;source=shareaholic" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;t=How+to+register+an+app+with+Twitter" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;title=How+to+register+an+app+with+Twitter" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;title=How+to+register+an+app+with+Twitter" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;title=How+to+register+an+app+with+Twitter" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;title=How+to+register+an+app+with+Twitter" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;title=How+to+register+an+app+with+Twitter" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/&amp;imageurl=" rel="nofollow" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
<li><a href='http://www.pakzilla.com/2010/04/13/download-gravity-a-symbian-s60-twitter-client/' rel='bookmark' title='Permanent Link: Download Gravity, a Symbian S60 Twitter client'>Download Gravity, a Symbian S60 Twitter client</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to avoid DeadlineExceededException in Google App Engine</title>
		<link>http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/</link>
		<comments>http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 23:00:30 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=641</guid>
		<description><![CDATA[
			
				
			
		
If you are developing web application on Google App Engine for Java. And you dont know what this exception is. You can be in trouble. The container throws this exception for those requests which take time more than 30 seconds. In other words GAE wants every requests to be fullfilled within 30 seconds.
Case
I am developing [...]


Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2010/07/16/fetch-twitter-friends-or-followers-through-rest-api-in-java/' rel='bookmark' title='Permanent Link: Fetch Twitter friends or followers through REST API in Java'>Fetch Twitter friends or followers through REST API in Java</a></li>
<li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F10%2F03%2Fhow-to-avoid-deadlineexceededexception-in-google-app-engine%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F10%2F03%2Fhow-to-avoid-deadlineexceededexception-in-google-app-engine%2F&amp;source=tahirakram&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>If you are developing web application on Google App Engine for Java. And you dont know what this <a href="http://code.google.com/appengine/docs/java/runtime.html#The%5FRequest%5FTimer">exception</a> is. You can be in trouble. The container throws this exception for those requests which take time more than 30 seconds. In other words GAE wants every requests to be fullfilled within 30 seconds.</p>
<p><strong>Case</strong><br />
I am developing a Twitter application and I got this exception when I login my Twitter user name. I have some 120 friends and 170 followers. So I need to fill two lists of Twitter users with their name and image URL. It was a bad practice from my side that I started populating lists in a loop which contain external service lookup overhead (Twitter) and also big in iteration. So I got following exception.<br />
<code>This request (670f658c2bf64b44) started at 2009/10/02 23:18:23.902 UTC and was still executing at 2009/10/02 23:18:52.605 UTC.</code></p>
<p><strong>Possible solution</strong><br />
As for those users who have friends and followers in thousands, this problem will persist. So what I am thinking is to put lists in session. Populate the page with first 30 users. And give a link to next 30 (paginate). I will keep updating two variables in session which will tell start and end to pick the users from the list. I will use <a href="http://directwebremoting.org/dwr/index.html">DWR</a> for this. By this my every request will be responded by container with in 30 seconds.</p>
<p>If you guys have some more optimum solution for it, please share me. Another solution has been discussed <a href="http://groups.google.com/group/google-appengine/browse_thread/thread/10c231dcd9d43a73">here</a> too.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=How+to+avoid+DeadlineExceededException+in+Google+App+Engine%3A+http://b2l.me/kpzzc+%28via+%40tahirakram%29+&amp;source=shareaholic" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;t=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;title=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;title=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;title=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;title=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;title=How+to+avoid+DeadlineExceededException+in+Google+App+Engine" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/&amp;imageurl=" rel="nofollow" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/' rel='bookmark' title='Permanent Link: Tutorial: Java based Twitter App on Google App Engine'>Tutorial: Java based Twitter App on Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2010/07/16/fetch-twitter-friends-or-followers-through-rest-api-in-java/' rel='bookmark' title='Permanent Link: Fetch Twitter friends or followers through REST API in Java'>Fetch Twitter friends or followers through REST API in Java</a></li>
<li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Java based Twitter App on Google App Engine</title>
		<link>http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/</link>
		<comments>http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 20:40:58 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=630</guid>
		<description><![CDATA[
			
				
			
		
Twitter a microblogging service is getting more and more popular these  days. A lot of developers are involved to develop applications on its  API.
Two weeks ago I click with a very basic idea and being as a matter of learning I started working on it. I have finished more than 80% of the work. I [...]


Related posts:<ol><li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
<li><a href='http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/' rel='bookmark' title='Permanent Link: How to avoid DeadlineExceededException in Google App Engine'>How to avoid DeadlineExceededException in Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/' rel='bookmark' title='Permanent Link: How to register an app with Twitter'>How to register an app with Twitter</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F10%2F03%2Ftutorial-java-based-twitter-app-on-google-app-engine%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.pakzilla.com%2F2009%2F10%2F03%2Ftutorial-java-based-twitter-app-on-google-app-engine%2F&amp;source=tahirakram&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="alignright size-full wp-image-705" title="google_app_engine_java" src="http://www.pakzilla.com/wp-content/upload/google_app_engine_java.png" alt="google_app_engine_java" width="117" height="106" /><a href="http://twitter.com/">Twitter </a>a microblogging service is getting more and more popular these  days. A lot of developers are involved to develop applications on its  <a href="http://apiwiki.twitter.com/">API</a>.</p>
<p>Two weeks ago I click with a very basic idea and being as a matter of learning I started working on it. I have finished more than 80% of the work. I deployed the application on <a href="http://www.pakzilla.com/2009/04/09/java-in-google-app-engine-whats-new-for-developers/">Google App Engine</a> (I hope you are familiar with it). I used <a href="http://yusuke.homeip.net/twitter4j/en/index.html">Twitter4J</a> lib a Java wrapper for Twitter API.</p>
<p>If you are also interested in Twitter based app development in Jave, then this tutorial will be helpful for you. Feel free to add comments at the end of the post, I will love to reply.</p>
<h4>Things you require for development</h4>
<ul>
<li><a href="http://www.eclipse.org/downloads">Eclipse IDE</a></li>
<li><a href="http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Java">Google App Engine SDK</a></li>
<li><a href="http://twitter.com/">A Twitter account</a></li>
<li><a href="http://yusuke.homeip.net/twitter4j/en/index.html">Twitter4J API</a></li>
</ul>
<h4>Things you need to know before you start</h4>
<p><strong>Oauth authentication</strong></p>
<p>You should know Oauth basics and its terminologies. You can little google on it or read this <a href="http://apiwiki.twitter.com/OAuth-FAQ">FAQs</a></p>
<p><strong>Register an App with Twitter</strong></p>
<p>You need to register an application on this URL: <a href="http://twitter.com/oauth">http://twitter.com/oauth</a>. Please take care of two things. The call back URL will not be your localhost URL. It should be a valid web address. And while choosing Default Access Type, if your application need to do changes or send tweets then you should choose Read &amp; Write otherwise/if you just want to do readonly operations then leave Read-only checked.</p>
<p><strong>A little bit about Google App Engine</strong></p>
<p>Google App Engine is cloud based hosting environment. You should read on their <a href="http://code.google.com/appengine/">web</a> or on a <a href="http://www.pakzilla.com/2009/04/09/java-in-google-app-engine-whats-new-for-developers/">post</a> by me.</p>
<h4>Steps for any Twitter App</h4>
<ol>
<li> User is on your website</li>
<li>Generate a token</li>
<li>Have a hyperlink and take user to the Twitter from your website for authentication</li>
<li>User will enter its user name and passeword and press allow<br />
If user&#8217;s credentials authentiecated Twitter will call the callback method which you had mentioned. Note that localhost URLs will not work here. You need mentiona a valid web address which will be invoked when user will be authenticated.</li>
</ol>
<h4>Code Section</h4>
<p>I will assume that you have developed a helloworld prject in Google App Engine and deployed it on appspot.com domain. Code snippet is available in 2 servlets and 1 jsp page.</p>
<p><strong>LoginServlet.java</strong></p>
<pre class="brush: java;">
Twitter twitter = new Twitter();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
RequestToken requestToken  = twitter.getOAuthRequestToken();

String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();

HttpSession session = request.getSession();
session.setAttribute(&quot;token&quot;, token);
session.setAttribute(&quot;tokenSecret&quot;, tokenSecret);

String authUrl = requestToken.getAuthorizationURL();

request.setAttribute(&quot;authUrl&quot;, authUrl);
RequestDispatcher rd = request.getRequestDispatcher(&quot;login.jsp&quot;);
rd.forward(request, response);
</pre>
<p>Consumer key and secrets will be generated when you register an application with Twitter. You need to keep token information into session so that you can use the token when callback URL will be called. authUrl is a link which will take user to the Twitter website for authentication. And if authentication successful it will call your URL mentioned as callback.</p>
<p><strong>login.jsp</strong></p>
<pre class="brush: java;">
&lt;a href='&lt;%=request.getAttribute(&quot;authUrl&quot;) %&gt;'&gt;Sign in with Twitter&lt;/a&gt;
</pre>
<p><strong>HomeServlet.java</strong> (as callback URL)</p>
<pre class="brush: java;">
Twitter twitter = new Twitter();
HttpSession session = request.getSession();

twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
AccessToken accessToken = twitter.getOAuthAccessToken(
(String) session.getAttribute(&quot;token&quot;), (String) session
.getAttribute(&quot;tokenSecret&quot;));
twitter.setOAuthAccessToken(accessToken);

User user = twitter.verifyCredentials();
</pre>
<p>HomeServlet is your callback. Let say you have mentioned URL mapping of this servlet as /Home. So you mention http://.appspot.com/Home in callback field in your app registeration page at twitter. And this HomeServlet will be called. Now you have the user object to play with. See <a href="http://yusuke.homeip.net/twitter4j/en/javadoc/index.html">Twitter4J javadocs</a> for more help.</p>
<p>WEB-INF/<strong>appengine-web.xml</strong></p>
<pre class="brush: xml;">&lt;sessions-enabled&gt;true&lt;/sessions-enabled&gt;</pre>
<p>You need to add this tag in you appengine-web.xml file that you are enabling the session.</p>
<p>So this was a tutorial, feel free to ping me on it. If you stuck somewhere. We will both look into it.</p>
<p>I also suggest following links to you people to must visit them. They helps me a lot in the understanding and the development. I will update this tutorial if got more things to discuss.</p>
<h4>Helpful Links</h4>
<ul>
<li><a href="http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/">How to Register an App with Twitter for OAuth</a></li>
<li><a href="http://www.snipe.net/2009/07/writing-your-first-twitter-application-with-oauth/">Writing Your First Twitter Application with OAuth</a></li>
<li><a href="http://jeungun.wordpress.com/2009/09/03/quick-and-dirty-twitter4j-oauth-for-web-apps/">Quick and Dirty Twitter4j OAuth for Web Apps</a></li>
<li><a href="http://research2009.wordpress.com/2009/08/24/finding-a-web-solution-for-twitter4j-results-of-session-solution/">Finding a Web Solution for Twitter4j: Results of Session Solution</a></li>
</ul>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine%3A+http://b2l.me/kp2jw+%28via+%40tahirakram%29+&amp;source=shareaholic" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;t=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;title=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;title=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;title=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;title=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;title=Tutorial%3A+Java+based+Twitter+App+on+Google+App+Engine" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/&amp;imageurl=" rel="nofollow" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>



<p>Related posts:<ol><li><a href='http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/' rel='bookmark' title='Permanent Link: How to use and retain Twitter4J OAuth access token'>How to use and retain Twitter4J OAuth access token</a></li>
<li><a href='http://www.pakzilla.com/2009/10/03/how-to-avoid-deadlineexceededexception-in-google-app-engine/' rel='bookmark' title='Permanent Link: How to avoid DeadlineExceededException in Google App Engine'>How to avoid DeadlineExceededException in Google App Engine</a></li>
<li><a href='http://www.pakzilla.com/2009/11/23/how-to-register-an-app-with-twitter/' rel='bookmark' title='Permanent Link: How to register an app with Twitter'>How to register an app with Twitter</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>
