rest我也尝试过 Postman ,但它给出了相同的错误@restcontroller@requestmapping()公共类rest{
@GetMapping("/tweet")
public void noticiaPost(){
String consumerKey = "AVlNWQzs3FYQ2DHsdDWY***";
String consumerSecret = "UL1PCQzBxm9kkEVDte3dgbgzgT7A*******";
String accessToken = "1281888984361308163-zqxjCD********";
String accessTokenSecret = "hMwcViNClKKjDj1TH751*****";
TwitterTemplate twitterTemplate =
new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
twitterTemplate.timelineOperations().updateStatus("hola buenos dias");
}
应用程序属性我从twitter开发者那里放置consumerkeys和accesstoken的应用程序属性
SpringAtSO.consumerKey=AVlNWQzs3FYQ*****
SpringAtSO.consumerSecret=UL1PCQzBxm9kkEVDt*****
SpringAtSO.accessToken=AAAAAAAAAAAAAAAAAAAAALk2WILF6Wr*******
错误我不明白这一点,我把所有的钥匙在控制器
2021-01-18 10:50:18.214 WARN 4396 --- [nio-8080-exec-1] o.a.h.c.protocol.ResponseProcessCookies : Invalid cookie header: "set-cookie: personalization_id="v1_wttGCbR3euCsc75cUIKYPQ=="; Max-Age=63072000; Expires=Wed, 18 Jan 2023 09:50:17 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None". Invalid 'expires' attribute: Wed, 18 Jan 2023 09:50:17 GMT
2021-01-18 10:50:18.214 WARN 4396 --- [nio-8080-exec-1] o.a.h.c.protocol.ResponseProcessCookies : Invalid cookie header: "set-cookie: guest_id=v1%3A161096341741656047; Max-Age=63072000; Expires=Wed, 18 Jan 2023 09:50:17 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None". Invalid 'expires' attribute: Wed, 18 Jan 2023 09:50:17 GMT
ERROR: 401 UNAUTHORIZED :: Could not authenticate you.
2021-01-18 10:50:18.240 ERROR 4396 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization.] with root cause
org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization.
at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleClientErrors(TwitterErrorHandler.java:100) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleError(TwitterErrorHandler.java:60) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:714) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:440) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:198) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:160) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
at com.Twitter.controller.REST.noticiaPost(REST.java:32) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
暂无答案!
目前还没有任何答案,快来回答吧!