首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推特模板直发失败,但获取限速请求有效

推特模板直发失败,但获取限速请求有效
EN

Stack Overflow用户
提问于 2018-06-14 17:03:28
回答 1查看 297关注 0票数 3

为什么不发送直通消息?

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

主类示例:

代码语言:javascript
复制
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构建文件中的依赖项:

代码语言:javascript
复制
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"
}

执行结果:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2018-06-16 00:32:14

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

https://apps.twitter.com/

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50853639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档