使用Spring social与Facebook登录

时间:2019-06-20 08:10:33

标签: facebook spring-social

我已经用Spring social和Spring boot创建了一个Facebook登录名,但是我遇到了关于org.springframework.social.facebook.api.Facebook的错误,找不到以下错误

com.morservs.demo.HelloController required a bean of type 'org.springframework.social.facebook.api.Facebook' that could not be found.

这是我的控制器 包com.morservs.demo;

import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Post;
import org.springframework.social.facebook.api.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

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

    private Facebook facebook;
    private ConnectionRepository connectionRepository;

    public HelloController(Facebook facebook, ConnectionRepository connectionRepository) {
        this.facebook = facebook;
        this.connectionRepository = connectionRepository;
    }

    @GetMapping
    public String helloFacebook(Model model) {
        if (connectionRepository.findPrimaryConnection(Facebook.class) == null) {
            return "redirect:/connect/facebook";
        }
        model.addAttribute("name", facebook.userOperations().getUserProfile());
        PagedList<Post> feed = facebook.feedOperations().getFeed();
        model.addAttribute("feed", feed);
        return "hello";
    }
}

hello.html

<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Hello Facebook</title>

</head>
<body>
<h3>Hello, <span th:text="${name}">Some User</span>!</h3>

<h4>Here is your feed:</h4>

0 个答案:

没有答案
相关问题