gpt4 book ai didi

java - Twitter 4j 中的 API 使用限制错误

转载 作者:行者123 更新时间:2023-12-02 04:42:36 24 4
gpt4 key购买 nike

这是我的程序,用于使用 Twitter 4j 使用我的应用程序更新我的 Twitter 状态

package hussi;
import java.util.logging.Logger;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;


public class test {
private final Logger logger = Logger.getLogger(test.class.getName());
public static void main(String[] args) {
new test().publish();
}

private void publish(){

String message="the long long week is over :) :) :)";

try {
Twitter twitter = new TwitterFactory().getInstance();
try {
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
while (null == accessToken) {
logger.fine("Open the following URL and grant access to your account:");
logger.fine(requestToken.getAuthorizationURL());
try {
accessToken = twitter.getOAuthAccessToken(requestToken);
}
catch (TwitterException te) {
if (401 == te.getStatusCode()) {
logger.severe("Unable to get the access token.");
} else {
te.printStackTrace();
}
}
}
logger.info("Got access token.");
logger.info("Access token: " + accessToken.getToken());
logger.info("Access token secret: " + accessToken.getTokenSecret());
}
catch (IllegalStateException ie) {
// access token is already available, or consumer key/secret is not set.
if (!twitter.getAuthorization().isEnabled()) {
logger.severe("OAuth consumer key/secret is not set.");
return;
}
}
Status status = twitter.updateStatus(message);
logger.info("Successfully updated the status to [" + status.getText() + "].");
}
catch (TwitterException te) {
te.printStackTrace();
logger.severe("Failed to get timeline: " + te.getMessage());
}
}
}

但是我在这一行遇到错误

Status status = twitter.updateStatus(message);

错误提示

SEVERE: Failed to get timeline: 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).
{"errors":[{"message":"SSL is required","code":92}]}

大家有什么建议吗?

它说要访问this link

但我不知道到底是什么原因导致的

最佳答案

您能够成功验证吗?我使用以下代码创建 twitter 对象:尝试一下!

public static ConfigurationBuilder confBuilder = null;
public static Configuration config = null;
public static Twitter twitterObj = null;

confBuilder = new twitter4j.conf.ConfigurationBuilder();
confBuilder.setDebugEnabled(true);

confBuilder.setOAuthConsumerKey(consumerKey);
confBuilder.setOAuthConsumerSecret(consumerSecret);
confBuilder.setOAuthAccessToken(accessToken);
confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);

config = confBuilder.build();

twitter4j.TwitterFactory tf = new twitter4j.TwitterFactory(config);
twitterObj = tf.getInstance();

关于java - Twitter 4j 中的 API 使用限制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22238050/

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