简体   繁体   English

使用 twitter4j 发布推文

[英]Post a Tweet with twitter4j

I have a twiiter app with:我有一个推特应用程序:

// Bearer token // 承载令牌

// API key // API 密钥

// API key secret // API 密钥

// Access token: // 访问令牌:

// Access token secret: // 访问令牌秘密:

and Read, Write, and Direct Messages permissions以及Read, Write, and Direct Messages权限

I use a ConfigurationBuilder class to configure Twitter4J programmatically in Java:我使用 ConfigurationBuilder class 在 Java 中以编程方式配置 Twitter4J:

ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
            .setOAuthConsumerKey("IX9qalH5azhSk61ZoFMiL83Jg")   // API key
            .setOAuthConsumerSecret("tidoT2GgVZE3B3txDb64tuinlv0wZHbKesX5bNIcjPWpxmcYcs") // API key secret
            .setOAuthAccessToken("1345093646195010258-goY3W4oyqSltGFSUNPwJy8pSjSmfI5") // Access token:
            .setOAuthAccessTokenSecret("ijkpYB8sacVcBdvKHOnh95Y3QRITzD3c4Uq8nUUMLTN8O"); //Access token secret:
    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf.getInstance();

But I have this error when I try to publish:但是当我尝试发布时出现此错误:

401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/media\/upload.json","error":"Read-only application cannot POST."}

I send the tweets from an Ubuntu server, already sync ( https://vitux.com/how-to-sync-system-time-with-internet-time-servers-on-ubuntu-20-04/ )我从 Ubuntu 服务器发送推文,已经同步( https://vitux.com/how-to-sync-system-time-with-internet-time-servers-on-ubuntu-20-04/

root@localhost:~# timedatectl
               Local time: Wed 2021-01-06 08:03:11 UTC
           Universal time: Wed 2021-01-06 08:03:11 UTC
                 RTC time: Wed 2021-01-06 08:03:12    
                Time zone: Etc/UTC (UTC, +0000)       
System clock synchronized: yes                        
              NTP service: active                     
          RTC in local TZ: no 

From this response below, I think you are using this API .从下面的回复中,我认为您正在使用此 API

401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/media\/upload.json","error":"Read-only application cannot POST."}

As there is an error message like below you need to create a Twitter application with Read & Write permissions.由于有如下错误消息,您需要创建一个具有读写权限的 Twitter 应用程序。 For more details about error messages, check this .有关错误消息的更多详细信息, 请查看此

Read-only application cannot POST.只读应用程序不能 POST。

Here is the official developer document about app permissions .这是关于应用权限的官方开发者文档。 Change this:改变这个: 只读应用 to this:对此: 读写应用

I hope, this is clear enough.我希望,这已经足够清楚了。

401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/media\/upload.json","error":"Read-only application cannot POST."}

As there is an error message like below you need to create a Twitter application with Read & Write permissions.由于有如下错误消息,您需要创建一个具有读写权限的 Twitter 应用程序。 For more details about error messages, check this.有关错误消息的更多详细信息,请检查此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM