如何在java中使用twitter4j发布推文? [英] how to post tweet using twitter4j in java?

查看:75
本文介绍了如何在java中使用twitter4j发布推文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 twitter4j 登录 Twitter 并获取有关登录用户的信息,但我无法从我的应用程序发布推文.我正在使用 Java Web 应用程序发布推文.请参阅下面我使用的代码.

I am able to login to twitter using twitter4j and get information about the logged in user but i am not able to post tweet from my application. I am using java web application to post tweet. see the code below that i use.

String ACCESS_TOKEN = "ttttttttt";
    String ACCESS_TOKEN_SECRET = "gggggggggggggg";
    String CONSUMER_KEY = "gggggggggggg";
    String CONSUMER_SECRET = "hhhhhhhhhhhhh";
    String tweet = "";
    if (request.getParameter("tweet") != null) {
        tweet = request.getParameter("tweet");
    }
    AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    OAuthAuthorization authorization = new OAuthAuthorization(ConfigurationContext.getInstance(), CONSUMER_KEY, CONSUMER_SECRET, accessToken);
    Twitter twitter = new TwitterFactory().getInstance(authorization);
    try {
        //twitter.updateStatus("Hello World!");
        twitter.updateStatus(tweet);
    } catch (TwitterException e) {
        System.err.println("Error occurred while updating the status!");
    }

我得到以下异常:

TwitterException{exceptionCode=[fa54b184-3bf2623f], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a8859cbd73d416474f4a8855

TwitterException{exceptionCode=[fa54b184-3bf2623f], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a855f3e889507)}

请帮忙.

推荐答案

  1. 转到您已创建的应用程序 (https://dev.twitter.com)

  1. Go to your already created application (https://dev.twitter.com)

检查您的应用程序设置(> 应用程序类型)

Check your application settings (> Application Type)

应用程序类型"需要是读取、写入和访问直接消息之一.如果没有,您可以轻松进行更新.

'Application Type' need to be one of Read, Write and Access direct messages. If not you can easily make an update.

(我在处理环境中测试了您的代码,并且可以正常工作)

(I tested your code in processing environment and it is working)

这篇关于如何在java中使用twitter4j发布推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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