Почему я получаю нулевое соединение с твиттером на примере руководства по Spring Boot / Spring Social?

Я следовал инструкциям на сайте spring.io: http://spring.io/guides/gs/accessing-twitter/

И я не получаю связь. Вызов "findPrimaryConnection()" возвращает ноль. Я не вижу никаких исключений. Я установил appId и appSecret в файле.properties.

Вот код контроллера:

@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) {
            System.out.println("******** no connection yet: " + connectionRepository.findPrimaryConnection(Twitter.class));
            return "redirect:/connect/twitter";
        }
        System.out.println("******** connection found");
        model.addAttribute(twitter.userOperations().getUserProfile());
        CursoredList<TwitterProfile> friends = twitter.friendOperations().getFriends();
        model.addAttribute("friends", friends);

        return "hello";
    }

}

Вот HTML-форма:

<form action="/connect/twitter" method="POST">
            <div class="formInfo">
                <p>You aren't connected to Twitter yet. Click the button to connect this application with your Twitter account.</p>
            </div>
            <p><button type="submit">Connect to Twitter</button></p>
        </form>

1 ответ

Вам необходимо установить URL-адрес обратного вызова в настройках приложения в Твиттере - это должно быть сказано в руководствах Spring.

Например, мое приложение работает с этим URL обратного вызова:

http://127.0.0.1:3000/auth/twitter/callback

введите описание изображения здесь

Это объясняется прямо под полем ввода:

URL обратного вызова: куда мы должны вернуться после успешной аутентификации? Приложения OAuth 1.0a должны явно указывать свой URL-адрес oauth_callback на шаге маркера запроса, независимо от значения, указанного здесь. Чтобы запретить вашему приложению использовать обратные вызовы, оставьте это поле пустым.

Другие вопросы по тегам