【问题标题】:spring-boot can I use FacebookAuthenticationService to connect with apiKey and appSecret?spring-boot 我可以使用 Facebook Authentication Service 连接 api Key 和 appSecret 吗?
【发布时间】:2016-06-07 08:15:11
【问题描述】:

在基于 spring-boot 的应用程序中,我会使用 apiKey 和 appSecret 获取 facebook 用户朋友进行连接,并使用 facebook 用户 ID 来识别用户(无用户访问令牌)。

我知道通过 facebook api graph 我可以使用 facebook api 端点 /{user-id}/friends 来获取用户好友列表,并且我可以使用应用令牌而不是用户访问令牌。

我正在尝试像这样实例化 Facebook:

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.security.FacebookAuthenticationService;
...
Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

但是当我在我的代码中包含这一行时,我得到了这个编译错误:

org.springframework.social.security.provider.OAuth2AuthenticationService 类型无法解析。它是从所需的 .class 文件中间接引用的

在 FacebookAuthenticationService.class 里面有

的导入
import org.springframework.social.security.provider.OAuth2AuthenticationService;

构建路径中不存在....我找不到

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-security</artifactId>

不像弹簧靴

<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>

但我不能包含第二个,因为在

的实例化过程中我会遇到不同的错误
        Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

错误是:

类型不匹配:无法从 FacebookAuthenticationService 转换为 Facebook

我想知道是否有人可以帮助我....

【问题讨论】:

    标签: facebook spring-boot


    【解决方案1】:

    据我了解,您的连接方式不需要 OAuth。 您希望服务器使用您已经拥有的凭据连接到 facebook,对吗? 比你必须使用 FacebookTemplate 连接。 我在一个项目中这样做,我只有

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-facebook</artifactId>
        </dependency>
    

    另请参阅我在 stackoverflow 35535091 上的回答

    【讨论】:

    • 是的,谢谢你打开我的心扉!我必须使用 new FacebookTemplate(appToken); (使用 appToken 而不是用户访问令牌)
    猜你喜欢
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多