我正在尝试使用spring.io访问Facebook,但isAuthorized()方法失败 [英] I am trying to access Facebook using spring.io social but the isAuthorized() method fails

查看:198
本文介绍了我正在尝试使用spring.io访问Facebook,但isAuthorized()方法失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 https://spring.io/guides/gs/访问Facebook access-facebook /

我使用导入Spring入门内容在Spring Tool Suite中导入了应用程序。我可以使用gradlew bootRun运行应用程序,并使用gradlew build。

I imported the application in Spring Tool Suite using "Import Spring Getting Started Content". I am able to run the application using "gradlew bootRun" and also using "gradlew build".

我遇到的问题是:看起来HelloController类中的测试

The problem I encounter is: It seems that in the HelloController class the test

if (!facebook.isAuthorized()) 

不工作。不执行剩余的语句并返回hello视图,应用程序继续执行语句

doesn't work. Instead of executing the remaining statements and a return to the "hello" view, the application keeps executing the statement

return "redirect:/connect/facebook"

,因为.isAutorized()方法失败。

as if the .isAutorized() method fails.

但是,当我在同一个webbrowser www.facebook.com中打开我比我的(登录)Facebook主页。使用该应用程序登录到Facebook似乎正常工作。请注意,在我测试申请之前,我明确地从Facebook注销。

However, when I open in the same webbrowser www.facebook.com than I get my (logged on) Facebook homepage. The login into Facebook using the application seems to work normally. Please note that I explicitly logout from Facebook before I test the application.

请注意:


  • 我已经在developer.facebook.com中注册了该应用程序。

  • 我将Facebook AppID和AppSecret提交到application.properties文件中。

  • 我在Facebook Apps网站URL中提交了一个使用Vitalwerks No-IP的hostname.domain。在我的路由器中,我将公共IP地址端口80映射到我的服务器
    端口8080的内部IP地址。我可以使用hostname.domain访问应用程序。

我做错了什么?控制器类看起来像这样:

What am I doing wrong? The controller class looks like this:

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

private Facebook facebook;

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

@RequestMapping(method=RequestMethod.GET)
public String helloFacebook(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";
}

}

推荐答案

在Facebook应用程序高级设置中,我的应用程序被配置为本机或桌面应用程序。这导致在OAuth呼叫期间发生错误400。

In the Facebook Apps Advanced settings my application was configured as a "Native or desktop app". This resulted in an Error 400 during the OAuth calls.

这篇关于我正在尝试使用spring.io访问Facebook,但isAuthorized()方法失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆