twitter api-spring身份验证错误

nnsrf1az  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(253)

rest我也尝试过 Postman ,但它给出了相同的错误@restcontroller@requestmapping()公共类rest{

  1. @GetMapping("/tweet")
  2. public void noticiaPost(){
  3. String consumerKey = "AVlNWQzs3FYQ2DHsdDWY***";
  4. String consumerSecret = "UL1PCQzBxm9kkEVDte3dgbgzgT7A*******";
  5. String accessToken = "1281888984361308163-zqxjCD********";
  6. String accessTokenSecret = "hMwcViNClKKjDj1TH751*****";
  7. TwitterTemplate twitterTemplate =
  8. new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
  9. twitterTemplate.timelineOperations().updateStatus("hola buenos dias");
  10. }

应用程序属性我从twitter开发者那里放置consumerkeys和accesstoken的应用程序属性

  1. SpringAtSO.consumerKey=AVlNWQzs3FYQ*****
  2. SpringAtSO.consumerSecret=UL1PCQzBxm9kkEVDt*****
  3. SpringAtSO.accessToken=AAAAAAAAAAAAAAAAAAAAALk2WILF6Wr*******

错误我不明白这一点,我把所有的钥匙在控制器

  1. 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
  2. 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
  3. ERROR: 401 UNAUTHORIZED :: Could not authenticate you.
  4. 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
  5. org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization.
  6. at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleClientErrors(TwitterErrorHandler.java:100) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
  7. at org.springframework.social.twitter.api.impl.TwitterErrorHandler.handleError(TwitterErrorHandler.java:60) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
  8. at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  9. at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  10. at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  11. at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:714) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  12. at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:440) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
  13. at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:198) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
  14. at org.springframework.social.twitter.api.impl.TimelineTemplate.updateStatus(TimelineTemplate.java:160) ~[spring-social-twitter-1.1.2.RELEASE.jar:1.1.2.RELEASE]
  15. at com.Twitter.controller.REST.noticiaPost(REST.java:32) ~[classes/:na]
  16. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
  17. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题