简体   繁体   English

如何通过Java Web应用程序使用户在其Twitter帐户中发布推文

[英]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 阅读本教程

  1. Import the 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目录内的草图文件夹中看到此文件。
  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: 我们将把本示例的内容放到安装程序外壳中,但是如果您愿意,可以将其包装到一个函数中或围绕它构建一个简单的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.

相关问题 如何使用Twitter4j在特定主题标签下检索用户及其关注者的推文? - How to retrieve tweets of user and his/her followers under a certain hashtag using Twitter4j? 如何使用twitter4j显示来自Twitter帐户的推文并使用Android应用程序发送相同的帐户? - How to display tweets from a twitter account and tweet that same account from an android app using twitter4j? 从Java登录到Twitter和Twitter(网络应用程序) - Login to twitter and tweet from Java (web-app) 如何确保用户没有在名为“名字”的第一个文本字段中输入他/她的全名 - How can I make sure that the user did not enter his/her entire name in the First Text Field named as "First Name" 如何从 Twitter API Java JSON 知道推文中的照片数量 - How to know the number of photos in a Tweet from Twitter API Java JSON 用户登录到他/她的帐户后,我正在尝试实施新的活动,但是登录完成后,应用程序仍然崩溃 - I'm trying to implement a new activity after a user logs into his/her account, but the app keeps crashing after sign in is complete 如何确保用户未在其姓名中输入数字? - How do I ensure that the user does not enter numbers in his / her name? 在Linked IN API中查找用户谁不共享他/她的Feed - Find user in Linked IN API Who does not share his /her feed 如何使用 twitter4j 获取用户时间线的完整推文? - how to get the full tweet of the user timeline with twitter4j? 如何为Java Web应用程序建立Web链接? - How to make a web link for a java web application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM