我试图在 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();
}