gpt4 book ai didi

java - 获取 Twitter 的 OAuthRequestToken 时连接超时

转载 作者:太空宇宙 更新时间:2023-11-04 07:22:23 25 4
gpt4 key购买 nike

您好,我正在尝试使用以下代码更新 Twitter 状态,但我不断收到以下异常,TwitterException{exceptionCode=[bfb606ed-4ef9708b bfb606ed-4ef97061]、statusCode=-1、message=null、code=-1、retryAfter=-1、rateLimitStatus=null、version=3.0.3}

我已经输入了正确的消费者“ key ”和消费者“ secret ”,感谢任何帮助!

    public void twitterUpdates(String update) throws TwitterException, IOException  {
// The factory instance is re-useable and thread safe.
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("key", "secret");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = loadAccessToken(twitter.verifyCredentials().getId());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (accessToken == null) {
System.out
.println("Open the following URL and grant access to your account:");
System.out.println(requestToken.getAuthorizationURL());
System.out
.print("Enter the PIN(if available) or just hit enter.[PIN]:");
String pin = br.readLine();
try {
if (pin.length() > 0) {
accessToken = twitter
.getOAuthAccessToken(requestToken, pin);
} else {
accessToken = twitter.getOAuthAccessToken();
}
} catch (TwitterException te) {
if (401 == te.getStatusCode()) {
System.out.println("Unable to get the access token.");
} else {
te.printStackTrace();
}
}
}
// persist to the accessToken for future reference.
storeAccessToken(twitter.verifyCredentials().getId(), accessToken);
Status status = twitter.updateStatus(update);
System.out.println("Successfully updated the status to ["
+ status.getText() + "].");


System.exit(0);
}

最佳答案

我也遇到了同样的异常,它来自调用 RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);原来是代理相关的问题。通过在 ConfigurationBuilder 中设置代理主机和端口来修复它:

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey(key);
cb.setOAuthConsumerSecret(secret);
cb.setHttpProxyHost("proxy");
cb.setHttpProxyPort(8080);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();

请注意,我还将callbackURL 传递给getOAuthRequestToken 方法:

RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);

关于java - 获取 Twitter 的 OAuthRequestToken 时连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19116600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com