gpt4 book ai didi

发送直接消息时 Twitter 模板失败,但获取速率限制请求有效

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

为什么没有发送直接消息?

spring-social-twitter:1.1.2.RELEASE 不适用于 spring-web:5.0.6.RELEASE

主类示例:

package com.test;
import org.springframework.social.twitter.api.ResourceFamily;
import org.springframework.social.twitter.api.impl.TwitterTemplate;

public class Main {
public static void main(String[] args) {
final TwitterTemplate template = new TwitterTemplate("TEST", "TEST","TEST", "TEST");
template.userOperations().getRateLimitStatus(ResourceFamily.DIRECT_MESSAGES);
System.out.println("Successfuly obtained rate limits");
System.out.println("Sending DM");
template.directMessageOperations().sendDirectMessage("user_id", "text");
}
}

来自 gradle 构建文件的依赖项:

dependencies {
compile "org.springframework:spring-web:5.0.6.RELEASE"
compile "org.springframework.social:spring-social-twitter:1.1.2.RELEASE"
compile "com.fasterxml.jackson.core:jackson-databind:2.9.5"
}

执行结果:

Successfuly obtained rate limits
Sending DM
Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api.twitter.com/1.1/direct_messages/new.json": cannot retry due to server authentication, in streaming mode; nested exception is java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:732)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:698)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:457)
at org.springframework.social.twitter.api.impl.DirectMessageTemplate.sendDirectMessage(DirectMessageTemplate.java:77)
at com.test.Main.main(Main.java:13)
Caused by: java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1692)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:55)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:51)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:754)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:724)
... 4 more

最佳答案

您没有提供 callback_url。转到您的 Twitter 应用设置页面:

https://apps.twitter.com/

并填写 Callback Url 输入字段。这将解决您的 I/O 问题。

关于发送直接消息时 Twitter 模板失败,但获取速率限制请求有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853639/

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