Research Log of Web Science Students

Computer Science is not simply programming

Posts Tagged ‘Google

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 »

Advertisements

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

Finding a Web Implementation for Twitter4J: Unsupported Property Types in Google App Engine DataStore

with one comment

(INTRO: I can’t seem to figure out how to use Twitter4j Oauth in a web app. The code in the website only gives examples in a main method.

Googling Twitter4j Tutorial Web and other related searches returns nil useful results. Through this series of blogposts I HOPE to be able address this dearth.

My Problem: I’d like to be able to access the RequestToken and Twitter instantiations after authorizing from Twitter)

I am trying to persist an instantiation of class RequestToken onto Google’s DataStore. This is so that I can use that and an instantiation of the twitter class after Twitter redirects my user to the callback URL right after authorization.

But my unit tests (thank God for Test Driven Development) give me the following errors:

dataStore_unSupported

The following screenshot shows my unit test and it does not even test anything! Read the rest of this entry »

Written by Jose Asuncion

August 24, 2009 at 4:02 pm

GAE On!

leave a comment »

Because our long term goal in building Projectrix is to be a standard in collaborative assessment, we must use clouds such as Google App Engine or Mor.ph. After the “serious” debate after our third presentation last August 10 about which cloud to use, Google App Engine versus Mor.ph, it was Paolo and Jeune’s Google App Engine that won. Though it was defeat on our part, we learned that App Engine is definitely the better choice. Below are some of the reasons why:

According to code.google,

  • App Engine is easy to get started.
  • Developers can take advantage of it’s automatic scalability. We just code and Google will do the rest for us!
  • App Engine is reliable, has excellent performance and secure.
  • App Engine offers Cost Efficient Hosting. It’s not expensive to get started with App Engine. If developers want bigger applications, additional fees are presented but definitely they’re worth it.
  • Free trial period is over! Developers would be happy because it’s free!
  • There are also many applications that use app engine already, meaning user base is established!
  • Has full support on Python and Java
  • Has brilliant documentation

=)

Written by Daniela

August 13, 2009 at 8:36 am

Posted in ProjectriX

Tagged with ,