Posts Tagged ‘Google’
Twitter4j Oauth + Spring: Class Twitter across multiple requests
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 »
New Problems with Twitter4j Oauth
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)
MethodInvokingBean: Wiring with two arguments in Spring
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>
My Quick and Dirty Twitter4j OAuth for Web Apps
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/
Finding a Web Implementation for Twitter4J: Unsupported Property Types in Google App Engine DataStore
(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:
The following screenshot shows my unit test and it does not even test anything! Read the rest of this entry »
