[英]How to make a user tweet into his/her twitter account from java web application
Hello I want to build an java web application in which I want the user to tweet on his account from my java application. 您好,我想构建一个Java Web应用程序,我希望用户在其中通过我的Java应用程序在其帐户上发布推文。
Now when we are considering twitter4J the code which is it shows is using our own registered application on twitter dev portal. 现在,当我们考虑twitter4J时,显示的代码正在Twitter开发人员门户上使用我们自己的注册应用程序。 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. 我想使用户从Java Web应用程序发送到他/她的Twitter帐户中。
Information I gathered 我收集的信息
http://blog.blprnt.com/blog/blprnt/quick-tutorial-twitter-processing http://blog.blprnt.com/blog/blprnt/quick-tutorial-twitter-processing
Read this tutorial 阅读本教程
twitter4j library
– you do this by simply dragging the twitter4j-2.0.8.jar
file onto your sketch window. 导入twitter4j library
–您只需将twitter4j-2.0.8.jar
文件拖到草图窗口中即可。 If you want to check, you should now see this file in your sketch folder, inside of a new code
directory. 如果要检查,现在应该在新code
目录内的草图文件夹中看到此文件。 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: 我们将把本示例的内容放到安装程序外壳中,但是如果您愿意,可以将其包装到一个函数中或围绕它构建一个简单的Class:
Twitter myTwitter = new Twitter("yourTwitterUserName", "yourTwitterPassword");
But now twitter 4j
is upgraded to 但是现在twitter 4j
已升级到
twitter4j-3.0.3
and now Twitter is an interface. 现在Twitter是一个界面。 What to do 该怎么办
As added by juned's answer below 如下面的juned的回答所补充
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. 因此,我知道Twitter为特定的注册应用程序提供了此密钥。 But I want to know for an random user from where to get this keys. 但我想为随机用户提供从哪里获得此密钥的信息。
I believe you cannot do it by simply using username and password. 我相信您不能仅使用用户名和密码来做到这一点。 You need to generate the key secret token and tokensecret. 您需要生成密钥秘密令牌和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: 然后,使用Java代码使用这些属性来获取对用户帐户的访问,以进行推文操作,以下是示例代码:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("*********************")
.setOAuthConsumerSecret("******************************************")
.setOAuthAccessToken("**************************************************")
.setOAuthAccessTokenSecret("******************************************");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.