我正在使用twitter4j-core-4.0.4.jar。
这是我的代码
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setUserStreamRepliesAllEnabled(true);
builder.setOAuthConsumerKey("myConusmerKey");
builder.setOAuthConsumerSecret("myConsumerSecret");
AccessToken accessToken = new AccessToken(pref.getString("ACCESS_TOKEN", ""), pref.getString("ACCESS_TOKEN_SECRET", ""));
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
File file = new File(picturePath);
StatusUpdate statusUpdate = new StatusUpdate(messageText.getText().toString());
Uri uri = Uri.parse(picturePath);
InputStream is = ScribbleFragment.this.getContentResolver().openInputStream(uri);
Log.d("Logger", "Sending media");
statusUpdate.setMedia(picturePath, is);
Log.d("Successfully sent media", "Sent media");
status = twitter.updateStatus(statusUpdate);
return status.toString();
这是我得到的回复,我用Google搜索但我没有找到任何答案
W/System.err: Failed to search tweets: 403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following). W/System.err: message - Error creating status. W/System.err: code - 189
答案 0 :(得分:0)
https://en.wikipedia.org/wiki/HTTP_403
这可能与您访问凭据有关。检查你如何获得访问令牌并确保它是有效的,因为403通常是一个错误,这意味着你没有被授权(禁止)访问数据。
答案 1 :(得分:0)
我认为您错误地设置了消费者密钥和消费者密钥。您应该将它们设置为Twitter中的值(或调用getString来检索它们)。目前,它们都被硬编码为看起来不正确的值。