从 Java 应用程序发布推文 [英] Posting tweets from a java application

查看:16
本文介绍了从 Java 应用程序发布推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Java 应用程序自动推文.最简单的方法是什么?我可以避免使用 Twitter4j 等库吗,

I want to auto tweet from a java application. What is the simplest way to do it? Can i avoid using libraries like Twitter4j etc.,

我需要一个简单的api的实现

I need an implementation for a simple api like

推文(用户名、密码、消息)..

Tweet(username, password, message)..

谢谢.

推荐答案

我建议您使用 twitter4j,使用它您可以轻松创建 oAuth 请求.Twitter 速率限制适用于桌面应用程序,为 150/小时.Twitter 不再支持使用用户名和密码进行基本身份验证.

I recommend you to use twitter4j and using this you can create oAuth requests easily. Twitter rate limits apply to desktop application and it is 150/hour. Twitter does not support basic authentication with username and password anymore.

您需要在 twitter 中创建一个应用程序并使用消费者密钥和秘密,只有您可以访问您的 twitter 帐户.

You are required to create an application in twitter and using the consumer key and secret only you can access your twitter account.

如果您要通过桌面应用程序访问推特,则必须选择应用程序类型:在创建应用程序时作为客户端".然后你可以使用下面的语法来更新你在 twitter 中的状态

If you are going to access the twitter by a desktop application then you have to select Application Type: as "Client" while creating the application. Then you can use the syntax below to update your status in twitter

 ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true)
                .setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(oAuthAccessToken)
                .setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
            TwitterFactory tf = new TwitterFactory(cb.build());
            Twitter twitter = tf.getInstance();
                    twitter.updateStatus("This is a test message"); //ThrowsTwitterException

我希望这对您有所帮助...如果这不是您想要的答案,请告诉我.实现您自己的 oAuth 请求涉及创建签名,这对我来说很复杂,而且对我们发送的时间和时间格式很敏感.

I hope this helps you... Please let me know if this is not the answer you were looking for. Implementing your own oAuth request involve creating signature that for me was complicated and it is sensitive to time and time format that we send.

这篇关于从 Java 应用程序发布推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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