微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用spring社交推特获得401(需要授权)

我一直在尝试这个Spring Social Accessing Twitter Data guide.虽然我已经加倍,三倍,所以检查了一切,当我点击“连接到Twitter”按钮时,我一直收到此错误

POST请求“https://api.twitter.com/oauth/request_token”导致401(需要授权);调用错误处理程序

这是我的代码

SRC /主/资源/模板/连接/ twitterConnect.html

SRC /主/资源/模板/连接/ twitterConnected.html

Now connected to your Twitter account.
        Click 

SRC /主/资源/模板/ hello.html的

的src / main / JAVA /你好/ HelloController.java

@Controller
@RequestMapping("/")
public class HelloController {

private Twitter twitter;

private ConnectionRepository connectionRepository;

@Inject
public HelloController(Twitter twitter,ConnectionRepository connectionRepository) {
    this.twitter = twitter;
    this.connectionRepository = connectionRepository;
}

@RequestMapping(method=RequestMethod.GET)
public String helloTwitter(Model model) {
    if (connectionRepository.findPrimaryConnection(Twitter.class) == null) {
        return "redirect:/connect/twitter";
    }

    model.addAttribute(twitter.userOperations().getUserProfile());
    CursoredList

的src / main / JAVA /你好/ Application.java

 @Configuration
    @EnableAutoConfiguration
    @ComponentScan
    public class Application {

    /*
     * SPRING BOOTSTRAP MAIN
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    }
最佳答案
我遇到了同样的问题.

经过一番调查后,我发现问题出现在回调网址中. Spring社交设置为yourap / signin / twitter.对于facebook和linkedin,这很好,但由于某种原因,twitter还需要在应用程序设置中填写回调网址.

所以解决方案:转到你的Twitter应用程序设置,并填写一个回调网址(这甚至不必是你要使用的实际回调网址,只需填写任何网址!).这很可能是造成问题的原因.

原文地址:https://www.jb51.cc/spring/431995.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐