Research Log of Web Science Students

Computer Science is not simply programming

Posts Tagged ‘GAE

Still Down :(

leave a comment »

As of the time on my computer (see screenshot) I am guessing we might not make it in time for Sunday. Ma’m Shelli and I will try to come up with a different play.

Written by Jose Asuncion

January 15, 2010 at 8:08 am

Twitter4j Oauth + Spring: Class Twitter across multiple requests

leave a comment »

The way I use the Twitter class in Twitter4j, I have to instantiate a new Twitter class for every request I receive.

For example in a Spring Controller,

Twitter twitter = new Twitter();

that’s very trivial to wire but my problem is what happens next:

Twitter twitter = new Twitter();
twitter.setOauthConsumer("consumerKey",consumerSecret");

How on earth will I wire something like that in Spring? Read the rest of this entry »

Written by Jose Asuncion

September 5, 2009 at 7:21 pm

New Problems with Twitter4j Oauth

leave a comment »

The problem: I can’t seem to get my profile image after authorization even if the logs show that I can get the url of my profile image!

What’s even more confusing is that I can get my screename and description, print them to the jsp but can’t do this:

<img src="${page['profileImage']}">

but in my servlet where I try to get the url of the image, the description and screename everything is printed in the logs just okay.

I am getting this twitter4j exception in my jsp

twitter4j.TwitterException: The user has not given access to the account.
	at twitter4j.http.HttpClient.getOAuthAccessToken(HttpClient.java:221)
	at twitter4j.Twitter.getOAuthAccessToken(Twitter.java:179)
	at com.hardwire.controller.AuthController.handleRequestInternal(AuthController.java:45)
	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)

Read the rest of this entry »

Written by Jose Asuncion

September 5, 2009 at 5:32 pm

MethodInvokingBean: Wiring with two arguments in Spring

leave a comment »

Another case of duplicating code in my app:

Twitter twitter = new Twitter();
twitter.setOAuthConsumer("consumerKey","consumerSecret");

The first solution I thought of was eliminate the duplicate code using dependency injection. Only that I thought you can only wire properties
one by one like for example:

<bean  id="MyPageController"
class="com.hardwire.controller.MyPageController">
 <property name="twitterService" ref="twitterService"/>
 <property name="userService" ref="googleUserService"/>
</bean>

But with Spring’s MethodInvokingBean, this can be instantiated and injected to the objects who need it.

<bean id="twitter" class="twitter4j.Twitter"></bean>

<bean id="twitterInjector" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="twitter"/>
<property name="targetMethod">
              <value>setOAuthConsumer</value>
</property>
<property name="arguments">
     <list>
       	<value>consumerKey</value>
       	<value>consumerSecret</value>
     </list>
 </property>
 </bean>    

Written by Jose Asuncion

September 3, 2009 at 6:06 pm

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/

Written by Jose Asuncion

September 3, 2009 at 5:26 pm