4

Hello I want to build an java web application in which I want the user to tweet on his account from my java application.

Now when we are considering twitter4J the code which is it shows is using our own registered application on twitter dev portal. Its is not asking for clients credentials. So please tell me how to figure out that I just want guidance not the code.

I read many post but all are confusing and I am not understanding.

I want to make the user tweet into his/her twitter account from java web application.

Information I gathered

http://blog.blprnt.com/blog/blprnt/quick-tutorial-twitter-processing

Read this tutorial

  1. Import the twitter4j library – you do this by simply dragging the twitter4j-2.0.8.jar file onto your sketch window. If you want to check, you should now see this file in your sketch folder, inside of a new code directory.
  2. We’ll put the guts of this example into the setup enclosure, but you could wrap it into a function or build a simple Class around it if you’d like:

    Twitter myTwitter = new Twitter("yourTwitterUserName", "yourTwitterPassword");

But now twitter 4j is upgraded to

twitter4j-3.0.3

and now Twitter is an interface. What to do

As added by juned's answer below

I have to supply for a particular user

oauth.consumerKey=*********************
oauth.consumerSecret=******************************************
oauth.accessToken=**************************************************
oauth.accessTokenSecret=******************************************

So I know for a particular registered app twitter provides this keys. But I want to know for an random user from where to get this keys.

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
Nikhil Agrawal
  • 26,128
  • 21
  • 90
  • 126
  • Hi Nikhil, I just came across the same problem as this. Could you pls share how did you do this using twitter4j? – samsamara Aug 28 '15 at 06:47

1 Answers1

3

I believe you cannot do it by simply using username and password. You need to generate the key secret token and tokensecret. Read these properties for example from a file:

oauth.consumerKey=*********************
oauth.consumerSecret=******************************************
oauth.accessToken=**************************************************
oauth.accessTokenSecret=******************************************

And then using java code use these properties to get the access to the user account for tweeting, here is the sample code:

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthConsumerKey("*********************")
  .setOAuthConsumerSecret("******************************************")
  .setOAuthAccessToken("**************************************************")
  .setOAuthAccessTokenSecret("******************************************");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • oauth.consumerKey=********************* oauth.consumerSecret=****************************************** oauth.accessToken=************************************************** oauth.accessTokenSecret=****************************************** – Nikhil Agrawal May 03 '13 at 05:31
  • these are there for our application how to make login from client credential. – Nikhil Agrawal May 03 '13 at 05:32
  • 1
    how to obtain these keys for an particular user – Nikhil Agrawal May 03 '13 at 08:14
  • @Er. Nikhil Agrawal see following [link] (https://dev.twitter.com/) then login into witter acount and then go to my application and then create one test application and this gives u all keys which u need....... Referense Link [link] (http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/) – Smily May 03 '13 at 08:51
  • @ArchanaA Ya I know but I wanna ask that this keys are different for different users.If not so using my keys how I make other users to post the tweets. – Nikhil Agrawal May 03 '13 at 08:54
  • @Er. Nikhil Agrawal sorry that i didnot try.. so no idea – Smily May 03 '13 at 08:56