views:

272

answers:

4

I am using twitter4j-2.1.3.jar to make a simple post to twitter. The code I use is:

System.setProperty("twitter4j.oauth.consumerKey", TWITTER_CONSUMER_KEY);
System.setProperty("twitter4j.oauth.consumerSecret",TWITTER_SECRET_KEY); 
Twitter twitter = new TwitterFactory().getInstance(username,password);
AccessToken accessToken = twitter.getOAuthAccessToken();
twitter.updateStatus(": xAuth test");

The error message I get is:

 TwitterException{exceptionCode=[e07c50ee-0000d883 1ac06e3f-626a1296], statusCode=401,   retryAfter=0, rateLimitStatus=null, version=2.1.3}

   at twitter4j.http.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:185)
   at twitter4j.TwitterOAuthSupportBaseImpl.getOAuthAccessToken(TwitterOAuthSupportBaseImpl.java:108)
   at twitter4j.Twitter.getOAuthAccessToken(Twitter.java:54)
   at com.sfway.detailpage.CheckinTab$16$1.run(CheckinTab.java:640)
   TwitterException{exceptionCode=[1ac06e3f-626a1296], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.3}
   at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:307)
   at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:72)
   at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:103)
   at twitter4j.http.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:178)

I tried an other way like this:

ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); 
configurationBuilder.setOAuthConsumerSecret(TWITTER_SECRET_KEY);
Configuration configuration = configurationBuilder.build();
twitter = new TwitterFactory(configuration).getInstance(username,password);
AccessToken token = twitter.getOAuthAccessToken();
twitter.updateStatus(": xAuth test");

In both methods I get the error at "twitter.getOAuthAccessToken()" line. Please let me know what is the wrong. I have registered my app exactly 14 hrs before, to get the secret and consumer key. Is this something to do with approval of my app for xAuth use, if yes how can I know whether they have enabled XAuth for my application at Twitter.

A: 

Did you check these posts??

http://groups.google.com/group/twitter4j/browse_thread/thread/d6dca9622f7cc42a?fwc=1

Switching the version has solved this issue for a person

<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>2.1.0</version>
</dependency> 
Rahul
hi rahul,I wonder how to add this dependency in Android,any idea.
ganesh
A: 

Hi Ganesh,

I have blog post on Twitter OAuth using Twitter4j and other libraries. You can follow that : http://blog.sogeti.com/mobile/2010/03/twitter-oauth-for-android.html

Also if you are using Twitter4j2.1.3 be awre that it is compatible with Android 2.0 and above. Let me know if you still face issues as I have a developed a complete Twitter app using Twitter4j 2.0.9.

Amit Chintawar
thanks a lot amit ,your post was very elaborate and wonderful ,but i i am using xauth,I will be glad to know why the above code failed.
ganesh
+1  A: 

Have you emailed Twitter support to get them to turn on xAuth for your application?

Twitter only want xAuth to be used by desktop and mobile applications, so registered applications have xAuth disabled by default, and you need someone at Twitter to turn it on for you. If you application doesn't have xAuth enabled, you get a 401.

To get xAuth enabled, send an email to [email protected] with the name of your application and the reason it needs xAuth instead of plain old OAuth (eg. it's not appropriate to pop up a web browser in my desktop application).

Thanks Dhrumil Shah

Dhrumil Shah
A: 

I agree with Dhrumil Shah: email Twitter at [email protected] to ask for your application to have xAuth enabled. It seems you have not yet done this, so then the xAuth service method will only return HTTP 401 when you call it.

peSHIr