Twitter API - Spring 身份验证错误

时间:2021-01-18 10:12:31

标签: java spring twitter spring-social-twitter

休息 我也试过邮递员,但它给出了同样的错误 @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 开发人员的消费密钥和访问令牌的应用程序属性

   SpringAtSO.consumerKey=AVlNWQzs3FYQ*****
    SpringAtSO.consumerSecret=UL1PCQzBxm9kkEVDt*****
    SpringAtSO.accessToken=AAAAAAAAAAAAAAAAAAAAALk2WILF6Wr*******

错误 我不明白这一点,我把所有的钥匙都放在了 restcontroller 中

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]
    

0 个答案:

没有答案