如何从 Java Web 应用程序将用户推文发送到他/她的推特帐户 [英] How to make a user tweet into his/her twitter account from java web application

查看:96
本文介绍了如何从 Java Web 应用程序将用户推文发送到他/她的推特帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想构建一个 Java Web 应用程序,我希望用户在其中通过我的 Java 应用程序在他的帐户上发推文.

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

现在,当我们考虑 twitter4J 时,它显示的代码正在使用我们自己在 twitter 开发门户上注册的应用程序.它不要求客户凭据.所以请告诉我如何确定我只需要指导而不是代码.

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.

我想让用户从 Java 网络应用程序推特到他/她的推特帐户.

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

我收集的信息

http://blog.blprnt.com/blog/blprnt/快速教程-推特处理

阅读本教程

  1. 导入 twitter4j 库 – 只需将 twitter4j-2.0.8.jar 文件拖到草图窗口即可.如果你想检查,你现在应该在你的草图文件夹中看到这个文件,在一个新的 code 目录内.
  2. 我们将把这个例子的内容放在设置附件中,但如果你愿意,你可以将它包装成一个函数或围绕它构建一个简单的类:

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

但是现在twitter 4j 升级为

twitter4j-3.0.3

现在 Twitter 是一个界面.怎么办

and now Twitter is an interface. What to do

正如下面 juned 的回答所添加的

我必须为特定用户提供

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

所以我知道 Twitter 为特定的注册应用程序提供了此密钥.但我想知道随机用户从哪里获得这些密钥.

推荐答案

我相信您不能仅使用用户名和密码来做到这一点.您需要生成密钥秘密令牌和 tokensecret.例如从文件中读取这些属性:

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=******************************************

然后使用java代码使用这些属性来获取对用户帐户的访问权限以进行推文,示例代码如下:

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

这篇关于如何从 Java Web 应用程序将用户推文发送到他/她的推特帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆