Error message is (#12) bio field is deprecated for versions v2.8 and higher

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

I used version 2.0.3.RELEASE of spring-social-facebook and Facebook app api v2.8. I called Facebook login but returned this message. "(#12) bio field is deprecated for versions v2.8 and higher" How can i fix this?

回答1:

I got the same error, 2.0.3.RELEASE of spring-social-facebook seems to be not compatible with v2.8 Facebook API version (released yesterday). Reading from facebook changelog for the v2.8 (https://developers.facebook.com/docs/apps/changelog):

User Bios - The bio field on the User object is no longer available. If the bio field was set for a person, the value will now be appended to the about field.

I think we have to wait a new release of spring-social-facebook library. In the release 2.0.3 (in the interface org.springframework.social.facebook.api.UserOperations) there is the "bio" field in the PROFILE_FIELDS constant and it is not supported in the v2.8 facebook API version.

UPDATE: I found a workaround in my case:

BEFORE:

Connection connection = facebookConnectionFactory.createConnection(accessGrant); Facebook facebook = connection.getApi(); User userProfile = facebook.userOperations().getUserProfile();//raises the exception caused by the "bio" field. 

AFTER

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

Here a complete list of field you could use:

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


回答2:

Workaround for JHipster. Add the following snippet into your SocialService class until spring-social-facebook is fixed.

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

Source: https://github.com/jhipster/generator-jhipster/issues/2349 - minus bio in fieldsToMap array.



回答3:

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 feed = facebook.feedOperations().getFeed();         model.addAttribute("feed", feed);         return "hello";     }  } 


回答4:

This has been fixed in new release of spring-social-facebook. Please add the following to your pom.xml

org.springframework.socialspring-social-facebook3.0.0.M1

If you get error that this version is not available, add the following as well.

alfresco-publichttps://artifacts.alfresco.com/nexus/content/groups/public


回答5:

Under grails spring security facebook I had a similar issue and thanks to @user6904265 I have managed to get it working:

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

Basically the default provided example above states User.class. This running locally was unable to find fields such as last_name etc and gave a list it could query. Those provided options were from the actual spring security User class (default to my app) so ensure you also look up correct user classes.



回答6:

I had problems with the new version of spring-social-facebook. To fix this using version 2.0.3.RELEASE paste the following code in your 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();     } } 

This code will not try to retrieve bio field from Facebook.

You can see more details here: https://github.com/jhipster/generator-jhipster/issues/2349



回答7:

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


回答8:

remove the parameter ->"bio" from your api call url, for me it solved

before "https://graph.facebook.com/v2.7/me/?fields=name,picture,work,website,religion,location,locale,link,cover,age_range,bio,birthday,devices,email,first_name,last_name,gender,hometown,is_verified,languages&access_token="

after

"https://graph.facebook.com/v2.7/me/?fields=name,picture,work,website,religion,location,locale,link,cover,age_range,birthday,devices,email,first_name,last_name,gender,hometown,is_verified,languages&access_token="



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!