gpt4 book ai didi

java - 461禁止 {"errors":[ {"message" :"SSL is required" ,"code":92}]} using Java

转载 作者:行者123 更新时间:2023-12-02 03:07:33 25 4
gpt4 key购买 nike

我正在开发 Twitter Rest 示例。在此示例中,我希望调用 Twitter REST API。当我运行下面的程序时,我看到错误。您能让我知道问题是什么吗?

public class JavaRestTweet {
static String consumerKeyStr = "RSvE3XXXXXXXXXXXX";
static String consumerSecretStr = "nKEWRoOcIXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
static String accessTokenStr = "1371430742-XXXXXXXXXXXXXXXXXXXXXXXXXX";
static String accessTokenSecretStr = "6ofNXMXXXXXXXXXXXXXXXXXXXXXXXXX";

public static void main(String[] args) throws Exception {
OAuthConsumer oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKeyStr, consumerSecretStr);
oAuthConsumer.setTokenWithSecret(accessTokenStr, accessTokenSecretStr);

HttpPost httpPost = new HttpPost(
"http://api.twitter.com/1.1/statuses/update.json?status=Hello%20Twitter%20World.");

oAuthConsumer.sign(httpPost);

HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpPost);

int statusCode = httpResponse.getStatusLine().getStatusCode();
System.out.println(statusCode + ':' + httpResponse.getStatusLine().getReasonPhrase());
System.out.println(IOUtils.toString(httpResponse.getEntity().getContent()));
}
}

错误:

461 Forbidden
{"errors":[{"message":"SSL is required","code":92}]}

pom.xml

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.2</version>
</dependency>

<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-commonshttp4</artifactId>
<version>1.2.1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>

<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

最佳答案

错误消息准确地告诉您需要了解的内容:

SSL is required

问题似乎是您在代码中使用 http://而不是 https://:

http://api.twitter.com/1.1/statuses/update.json

关于java - 461禁止 {"errors":[ {"message" :"SSL is required" ,"code":92}]} using Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41553283/

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