0

我试图在 Twitter 上发布状态更新。我正在使用 Twitter4j 库。我的代码运行没有崩溃,但在日志中 cat 说“401:身份验证凭据(https://dev.twitter.com/pages/auth)丢失或不正确。确保您设置了有效的消费者密钥/秘密,访问令牌/secret,系统时钟同步。

{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."}

有什么帮助吗?我已经在 Twitter 上注册了,我检查了读写权限。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Runnable runnable = new Runnable() {
        public void run() {
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.setOAuthConsumerKey("kkwfh72794883jjg");
            builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");



            // Access Token
            String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
            // Access Token Secret
            String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";

            AccessToken accessToken = new AccessToken(access_token, access_token_secret);
            Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

            // Update status
            try {
                twitter4j.Status response = twitter.updateStatus("updated via myapp");

                Log.d("Status", "> " + response.getText());

                // Error in updating status


                } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.d("Twitter Update Error", e.getMessage());
            }


        }
    };
    Thread mythread = new Thread(runnable);
    mythread.start();


}
4

2 回答 2

0

我有类似的问题。我所做的是:

  1. 检查您的应用是否具有读取和写入权限
  2. 如果没有,请检查权限单选按钮,然后单击更新设置
  3. 之后,您必须手动重新生成访问令牌(我也重新生成了消费者密钥)

希望这对其他奋斗者有所帮助。

于 2015-06-19T09:56:44.183 回答
0

我认为你应该改变你的代码:像这样:

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey("kkwfh72794883jjg");
builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");
OAuthAuthorization auth = new OAuthAuthorization(builder.build());
// Access Token
String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
// Access Token Secret
String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";
Twitter twitter = new TwitterFactory().getInstance(auth);
于 2017-03-09T11:17:07.997 回答