twitter4j:即使我已经设置了凭证错误?
package twitter4j.examples.tweets;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.conf.*;
import java.io.IOException;
public final class UpdateStatus {
public static void main(String[] args) throws IOException {
String testPost = "hello from otc";
String consumerKey = "key";
String consumerSecret = "secret";
String accessToken = "access";
String accessSecret = "access_secret";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessSecret);
try {
TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
AccessToken accestoken = new AccessToken(accessToken, accessSecret);
twitter.setOAuthAccessToken(accestoken);
Status status = twitter.updateStatus(testPost);
System.out.println("it worked!");
if (status.getId() == 0) {
System.out
.println("Error occured while posting tweets to twitter");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
为什么我不断收到此错误:
401:身份验证凭据 (http://dev.twitter.com/pages/auth) 丢失或不正确。确保您已设置有效的消费者密钥/秘密、访问令牌/秘密以及同步的系统时钟。 错误 - 无法使用 OAuth 进行身份验证。 请求 - /1/statuses/update.json 相关讨论可以在网上进行: http://www.google.co.jp/search?q=e06d87a8或者 http://www.google.co.jp/search?q=5851cbdb TwitterException{exceptionCode=[e06d87a8-5851cbdb],statusCode=401,retryAfter=-1,rateLimitStatus=null,featureSpecificRateLimitStatus=null,version=2.2.3} 在 twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189) 在 twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) 在 twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102) 在 twitter4j.TwitterImpl.post(TwitterImpl.java:1871) 在 twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:459) 在 twitter4j.examples.tweets.UpdateStatus.main(UpdateStatus.java:35)
我已经在文件中设置了凭据,不是吗?
package twitter4j.examples.tweets;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.conf.*;
import java.io.IOException;
public final class UpdateStatus {
public static void main(String[] args) throws IOException {
String testPost = "hello from otc";
String consumerKey = "key";
String consumerSecret = "secret";
String accessToken = "access";
String accessSecret = "access_secret";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessSecret);
try {
TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
AccessToken accestoken = new AccessToken(accessToken, accessSecret);
twitter.setOAuthAccessToken(accestoken);
Status status = twitter.updateStatus(testPost);
System.out.println("it worked!");
if (status.getId() == 0) {
System.out
.println("Error occured while posting tweets to twitter");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
why do i keep getting this error:
401:Authentication credentials (http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
error - Could not authenticate with OAuth.
request - /1/statuses/update.json
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=e06d87a8 or
http://www.google.co.jp/search?q=5851cbdb
TwitterException{exceptionCode=[e06d87a8-5851cbdb], statusCode=401, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1871)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:459)
at twitter4j.examples.tweets.UpdateStatus.main(UpdateStatus.java:35)
i have set the credentials in the file already, have i not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这是一个工作代码:
注意:要使其工作,您必须在 Twitter 上创建一个应用程序
您必须有一个 twitter4j.properties 文件,其中包含以下
所有密钥和令牌都来自 twitter 应用程序
确保您的应用程序访问级别都为“读和写”
i figured it out heres a working code:
note: for this to work you MUST create an application on twitter
you must have a twitter4j.properties file which contain the following
all the keys and tokens are from the twitter application
make sure your application access level all say "read and write"