Research Log of Web Science Students

Computer Science is not simply programming

My Quick and Dirty Twitter4j OAuth for Web Apps

with 2 comments

This simple tutorial is a result of my trying to oauth to twitter using Twitter4j. This is a small functionality in my thesis. Anyway, I have been googling tutorials on how to use Twitter4j in a web app but I haven’t found much. The Twitter4j has examples but most of them in are written in a main method. I did find some a lead in the Twitter4j google group and much to my surprise, the key to accessing data in Twitter using Twitter4j/Oauth is knowing how Oauth works in the first place.

This tutorial isn’t about how to use the oauth protocol there are many resources in the net about that .

Try here, here and well, here.

Although this code works, it might not be the right way to use Twitter4j and Oauth. It might not be optimized and it’s definitely not the best way. It’s actually riddled with bad practices! Although in my real app, I have refactored those code smells already.

Another thing, I have yet to address why Twitter’s icon shows up after it redirects to the to callback url. I intend to work on that issues soon as well as optimizing the method. Comments and suggestions are highly welcome!

http://jeungun.wordpress.com/2009/09/03/quick-and-dirty-twitter4j-oauth-for-web-apps/

Advertisements

Written by Jose Asuncion

September 3, 2009 at 5:26 pm

2 Responses

Subscribe to comments with RSS.

  1. […] have been attempting to wire Twitter4j in Spring for the past two days now. Although we’ve been successful at accessing Twitter data using Oauth already, I wasn’t satisfied at just making the code work. What we came up with was a “code […]

  2. Hi,

    I have integrated Twitter4j login functionality for my project successfully with your article but on deny of logging giving me exception. Below are the steps i did

    Step.1) if i click on twitter button takes me to twitter login pop up
    box with “Allow” and “Deny” buttons

    Step.2) if i enter proper twitter username and password, it is
    redirecting me to the twitter call back url which is to my application
    url.

    Upto this everything is working fine.

    Step.3) After (Step.1), if i click on “Deny” button it is redirecting
    to the twitter popup box with some information(OK, you’ve denied
    localvc access to interact with your account! Feel free to find other
    applications and find out what people are talking about right now at
    Twitter.).

    Then closed the twitter popup box, if i comes back to my app login
    page it is giving me exception “Stack Overflow”.

    If i close the browser, reopen the new browser and then i could able
    to access the my app login page without any problem.

    How can i resolve the ‘Stack overflow exception’ issue after clicking
    “Deny” button?
    Is there any functionality to take care on “Deny” button?

    StackOverflow exception:

    Caused by: javax.servlet.ServletException:
    java.lang.StackOverflowError
    at
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:
    855)
    at
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:
    784)
    at org.apache.jsp.jsp.user.login_jsp._jspService(login_jsp.java:362)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
    384)
    at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
    320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
    290)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
    206)
    at
    org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:
    687)
    at
    org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:
    590)
    at
    org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:
    505)
    at
    org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:
    968)
    at
    org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:
    643)
    at
    org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:
    637)
    at
    org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:
    80)
    … 93 more
    Caused by: java.lang.StackOverflowError
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    445)
    at twitter4j.http.RequestToken.hashCode(RequestToken.java:95)
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    447)
    at twitter4j.http.RequestToken.hashCode(RequestToken.java:95)
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    447)
    at twitter4j.http.RequestToken.hashCode(RequestToken.java:95)
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    447)
    at twitter4j.http.RequestToken.hashCode(RequestToken.java:95)
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    447)
    at twitter4j.http.RequestToken.hashCode(RequestToken.java:95)
    at twitter4j.http.OAuthAuthorization.hashCode(OAuthAuthorization.java:
    447)

    venkatareddy.pammi

    June 18, 2010 at 3:09 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: