spring 社交推特 MissingAuthorizationException

spring social twitter MissingAuthorizationException

我尝试 post 使用 Spring 社交的推文,如本教程所述:https://docs.spring.io/spring-social-twitter/docs/current/reference/htmlsingle/。但是我得到

org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization.

我的代码如下所示

TwitterTemplate twitterTemplate = new TwitterTemplate("key", "secret");
TweetData tweetData =new TweetData("test screenshot").withMedia(new ByteArrayResource(object.getScreenshot().getBytes()));
Tweet postResult = twitterTemplate.timelineOperations().updateStatus(tweetData);

某些操作需要单独的访问令牌与 TwitterTemplate 一起传递:

new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);

可以在此处生成访问令牌:apps.twitter.com/app/"appId"/keys