Spring Social Facebook获得Whitelabel

时间:2019-04-21 16:30:01

标签: java gradle spring-social-facebook

大家好,尽管我已经从他们的网站关注了春季教程,但我仍然收到此错误。我一直在试图弄清楚为什么我得到这个错误。我可以连接到Facebook,但是当尝试检索诸如spring提供的教程之类的提要时,我总是收到whitelabel错误。它说:

此应用程序没有针对/ error的显式映射,因此您将其视为后备。发生意外错误(类型=未找到,状态= 404)。没有可用消息

一切似乎都还可以,但不知道为什么我总是收到此错误。如果有人可以提供帮助,我将不胜感激。

我的控制器放在src / main / java / home / Controller中:

@Controller
@RequestMapping(value="/")
public class HomeController {

private Facebook facebook;

@Inject
public HomeController(Facebook facebook) {
    this.facebook = facebook;
}

@RequestMapping( method =RequestMethod.GET)
public String getPhotos(Model model){

    if(!facebook.isAuthorized())
    {
        return "redirect:/connect/facebook";
    }
    model.addAttribute(facebook.userOperations().getUserProfile());
    PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
    model.addAttribute("feed", homeFeed);

    return "hello";
 }
}

位于src / main / java / home中的Application.java文件:

@SpringBootApplication
 public class Application {
 public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

下面是我的build.gradle文件:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

buildscript{
repositories{
   // maven { url "https://repo.spring.io/release" }
    maven { url "https://repo.spring.io/libs-milestone"}
   // mavenCentral()
      }
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
  }
 }
repositories {
   maven { url "https://repo.spring.io/libs-milestone"}
   mavenCentral()
 }
bootRepackage {
  mainClass = 'facebookArchiver.Application'
}
 dependencies {
  compile ('org.springframework.social:spring-social-facebook:2.0.0.RELEASE')
  compile("org.springframework.boot:spring-boot-starter-thymeleaf")
  compile('org.springframework.boot:spring-boot-starter-web')
  testCompile group: 'junit', name: 'junit', version: '4.11'
 }
 task wrapper(type: Wrapper) {
      gradleVersion = '2.3'
 }

hello.html文件:保存在src / main / resources / templates文件夹中:

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

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

 <div th:each="post:${feed}">
 <b th:text="${post.from.name}">from</b> wrote:
 <p th:text="${post.message}">message text</p>
 <img th:if="${post.picture}" th:src="${post.picture}"/>
 <hr/>
 </div>
</body>
</html>

facebookConnect.html:它存储在src / main / resources / templates / connect

folder:
<html>
 <head>
 <title>Hello Facebook</title>
 </head>
 <body>
  <h3>Connect to Facebook</h3>

  <form action="/connect/facebook" method="POST">
<input type="hidden" name="scope" value="read_stream" />
  <div class="formInfo">
    <p>You aren't connected to Facebook yet. Click the button to connect  this application with your Facebook account.</p>
 </div>
 <p><button type="submit">Connect to Facebook</button></p>
</form>
</body>
</html>

最后是facebookConnected.html:也存储在src / main / resources / templates / connect文件夹下:以下是facebookConnected.html的文件:

<html>
<head>
  <title>Hello Facebook</title>
</head>
  <body>
   <h3>Connected to Facebook</h3>
   <p>
     You are now connected to your Facebook account.
    Click <a href="/">here</a> to see some entries from your Facebook photos.
  </p>
</body>
</html>

0 个答案:

没有答案