问题描述
我在使用 twitter4j 发推文时遇到问题,有时会抛出错误
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.
message - Could not authenticate you.
code - 32
有时我在使用它时根本没有收到错误并且推文发送正确,所以我相信这不是 api 密钥/秘密的错误。
如果我尝试使用 twitter.verifyCredentials()
方法,则会正确返回用户。我在返回的用户中看不到任何错误信息。
这有点像我使用的java代码:
public static twitter4j.Twitter getTwitter(
String apiKey,String secret,String oauthToken,String oauthSecret) {
final ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setoAuthConsumerKey(apiKey)
.setoAuthConsumerSecret(secret)
.setoAuthAccesstoken(oauthToken)
.setoAuthAccesstokenSecret(oauthSecret)
.setTweetModeExtended(true);
final TwitterFactory tf = new TwitterFactory(cb.build());
twitter4j.Twitter t = tf.getInstance();
return t;
}
public static void tweet(
String apiKey,String oauthSecret,String message)
throws TwitterException {
twitter4j.Twitter twitter = getTwitter(apiKey,secret,oauthToken,oauthSecret);
Status status = twitter.updateStatus(message);
}
public static void main(String[] args) throws TwitterException {
Keyword k = Keyword.load(1);
String msg = "This is a test tweet";
tweet(
k.getTwitterapiKey(),k.getTwitterapiSecret(),k.getTwitterOAuthToken(),k.getTwitterOAuthSecret(),msg);
}
感谢任何帮助。如果我需要提供更多信息,请告诉我。
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)