How to make a user tweet into his/her twitter account from java web application

落爺英雄遲暮 提交于 2019-12-23 21:13:15

问题


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.


回答1:


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();


来源:https://stackoverflow.com/questions/16351794/how-to-make-a-user-tweet-into-his-her-twitter-account-from-java-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!