twitter - Twitter模板在发送直接消息期间失败,但获取速率限制请求有效
问题描述
为什么不发送直接消息?
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
解决方案
推荐阅读
- emacs - 使用 cl-json 打开大文件时,Slime 会导致连接被远程对等方断开
- go - 使用反射访问结构字段(作为字符串变量)与直接访问它的性能
- github - 如何在 GitHub 操作作业中创建下拉列表
- javascript - 使用 Fabric.JS 在画布中围绕弧或圆的弯曲文本
- angular - Angular ng-select group by parents collaspe
- java - 为什么 Redisson RLocalCachedMap 有时会调用“DEL”命令?
- apache-flink - Flink MySql 查找加入延迟
- wordpress - 使用 Mailchimp API 从 woocommerce 中的 mailchimp 获取成员详细信息时出错
- javascript - 如何从异步方法访问 Vue 中的数据字段?
- python - 将 ffmpeg 上传到 Azure 函数环境 PATH [Python]