对于版本v2.8及更高版本,不推荐使用错误消息(#12)生物字段

Ans*_*Kim 31 spring-social-facebook

我使用了版本2.0.3.RELEASE的spring-social-facebook和Facebook app api v2.8.我打电话给Facebook登录但是返回了此消息."(#12)生物领域不适用于版本v2.8及更高版本"我该如何解决这个问题?

use*_*265 54

我得到了同样的错误,2.0.3.RELEASE的spring-social-facebook似乎与v2.8 Facebook API版本(昨天发布)不兼容.从facebook更新日志中读取v2.8(https://developers.facebook.com/docs/apps/changelog):

用户Bios - User对象上的bio字段不再可用.如果为某人设置了生物场,则该值将附加到about字段.

我想我们必须等一下spring-social-facebook库的新版本.在2.0.3版本中(在org.springframework.social.facebook.api.UserOperations界面中),PROFILE_FIELDS常量中存在"bio"字段,v2.8 facebook API版本不支持该字段.

更新:我在我的案例中找到了一个解决方法:

之前:

Connection<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
Facebook facebook = connection.getApi();
User userProfile = facebook.userOperations().getUserProfile();//raises the exception caused by the "bio" field.
Run Code Online (Sandbox Code Playgroud)

Connection<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
Facebook facebook = connection.getApi();
String [] fields = { "id", "email",  "first_name", "last_name" };
User userProfile = facebook.fetchObject("me", User.class, fields);
Run Code Online (Sandbox Code Playgroud)

这里有一个完整的字段列表,您可以使用:

{ "id", "about", "age_range", "birthday", "context", "cover", "currency", "devices", "education", "email", "favorite_athletes", "favorite_teams", "first_name", "gender", "hometown", "inspirational_people", "installed", "install_type", "is_verified", "languages", "last_name", "link", "locale", "location", "meeting_for", "middle_name", "name", "name_format", "political", "quotes", "payment_pricepoints", "relationship_status", "religion", "security_settings", "significant_other", "sports", "test_group", "timezone", "third_party_id", "updated_time", "verified", "video_upload_limits", "viewer_can_send_gift", "website", "work"}
Run Code Online (Sandbox Code Playgroud)


Mic*_*ksa 29

JHipster的解决方法.将以下代码段添加到您的SocialService班级中,直到spring-social-facebook修复为止.

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import javax.annotation.PostConstruct;

@PostConstruct
private void init() {
    try {
        String[] fieldsToMap = { "id", "about", "age_range", "birthday",
                "context", "cover", "currency", "devices", "education",
                "email", "favorite_athletes", "favorite_teams",
                "first_name", "gender", "hometown", "inspirational_people",
                "installed", "install_type", "is_verified", "languages",
                "last_name", "link", "locale", "location", "meeting_for",
                "middle_name", "name", "name_format", "political",
                "quotes", "payment_pricepoints", "relationship_status",
                "religion", "security_settings", "significant_other",
                "sports", "test_group", "timezone", "third_party_id",
                "updated_time", "verified", "viewer_can_send_gift",
                "website", "work" };

        Field field = Class.forName(
                "org.springframework.social.facebook.api.UserOperations")
                .getDeclaredField("PROFILE_FIELDS");
        field.setAccessible(true);

        Field modifiers = field.getClass().getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, fieldsToMap);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

来源:https://github.com/jhipster/generator-jhipster/issues/2349 -减biofieldsToMap阵列.


Hei*_*erg 11

这已在spring-social-facebook的新版本中得到修复.请将以下内容添加到您的pom.xml中

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-facebook</artifactId>
    <version>3.0.0.M1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

如果您收到此版本不可用的错误,请添加以下内容.

<repositories>
    <repository>
        <id>alfresco-public</id>
        <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
    </repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)


小智 8

package hello;

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";
        }
        String [] fields = { "id","name","birthday","email","location","hometown","gender","first_name","last_name"};
        User user = facebook.fetchObject("me", User.class, fields);
        String name=user.getName();
        String birthday=user.getBirthday();
        String email=user.getEmail();
        String gender=user.getGender();
        String firstname=user.getFirstName();
        String lastname=user.getLastName();
        model.addAttribute("name",name );
        model.addAttribute("birthday",birthday );
        model.addAttribute("email",email );
        model.addAttribute("gender",gender);
        model.addAttribute("firstname",firstname);
        model.addAttribute("lastname",lastname);
        model.addAttribute("facebookProfile", facebook.fetchObject("me", User.class, fields));
        PagedList<Post> feed = facebook.feedOperations().getFeed();
        model.addAttribute("feed", feed);
        return "hello";
    }

}
Run Code Online (Sandbox Code Playgroud)


joa*_*ego 5

我遇到了spring-social-facebook新版本的问题.为了解决这个问题使用的版本2.0.3.RELEASE粘贴到下面的代码SocialService.java

@PostConstruct
private void init() {
    try {
        String[] fieldsToMap = {
            "id", "about", "age_range", "birthday", "context", "cover", "currency", "devices", "education", "email", "favorite_athletes", "favorite_teams", "first_name", "gender", "hometown", "inspirational_people", "installed", "install_type","is_verified", "languages", "last_name", "link", "locale", "location", "meeting_for", "middle_name", "name", "name_format","political", "quotes", "payment_pricepoints", "relationship_status", "religion", "security_settings", "significant_other","sports", "test_group", "timezone", "third_party_id", "updated_time", "verified", "viewer_can_send_gift","website", "work"
        };

        Field field = Class.forName("org.springframework.social.facebook.api.UserOperations").
                getDeclaredField("PROFILE_FIELDS");
        field.setAccessible(true);

        Field modifiers = field.getClass().getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, fieldsToMap);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码不会尝试从Facebook 检索生物领域.

您可以在此处查看更多详细信息:https://github.com/jhipster/generator-jhipster/issues/2349


归档时间:

查看次数:

15735 次

最近记录:

7 年,3 月 前