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

时间:2016-10-06 08:14:23

标签: spring-social-facebook

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

9 个答案:

答案 0 :(得分:52)

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

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

我认为我们必须等一下spring-social-facebook库的新版本。在2.0.3版本中(在org.springframework.social.facebook.api.UserOperations界面中)有" bio" PROFILE_FIELDS常量中的字段,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.

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);

这里有一个完整的字段列表:

{ "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"}

答案 1 :(得分:29)

JHipster的解决方法。将以下代码段添加到Set Fileout = fso.OpenTextFile("C:\Test.txt", 8, True) 课程中,直到SocialService修复。

spring-social-facebook

来源:https://github.com/jhipster/generator-jhipster/issues/2349 - 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(); } } 数组中的减去bio

答案 2 :(得分:11)

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

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-facebook</artifactId>
    <version>3.0.0.M1</version>
</dependency>

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

<repositories>
    <repository>
        <id>alfresco-public</id>
        <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
    </repository>
</repositories>

答案 3 :(得分: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";
    }

}

答案 4 :(得分: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();
    }
}

此代码不会尝试从Facebook检索 bio 字段。

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

答案 5 :(得分:1)

在grails spring security facebook下我遇到了类似的问题 感谢@ user6904265我设法让它运转起来:

 190
 200
 250
 350
 90

上面提供的默认示例基本上是//This was provided example method: //org.springframework.social.facebook.api.User fbProfile = facebook.userOperations().userProfile //This is the groovy way of declaring fields: String[] fields = ['id',"email", "age_range", "birthday","first_name", "last_name","gender"] as String[] //This bit pay attention to the User.class segment. org.springframework.social.facebook.api.User fbProfile = facebook.fetchObject("me", org.springframework.social.facebook.api.User.class, fields) 。本地运行无法找到last_name等字段,并提供了可以查询的列表。提供的选项来自实际的Spring安全性User类(默认为我的应用程序),因此请确保您也查找正确的用户类。

答案 6 :(得分:0)

FacebookTemplate template = new FacebookTemplate(access_token); 
String [] fields = { "id", "email",  "first_name", "last_name" };
User profile = template.fetchObject("me", User.class, fields);

答案 7 :(得分:0)

答案 8 :(得分:0)

我在项目中复制了界面 UserOperations ,更改了 PROFILE_FIELDS ,删除了生物字段。在Tomcat上,我编辑的类优先于org.springframework.social.facebook.api.UserOperations接口,这就解决了这个问题。 (参见下面文件的最后一行)

FormatException

}