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

9

32

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?

Antionetteantioxidant answered 6/10, 2016 at 8:14 Comment(3)
There is a PR waiting merge to fix this issue: github.com/spring-projects/spring-social-facebook/pull/218Semivowel
Any idea when the fix would go through? It's still stuck there at 2.0.3Dambro
The PR has been merged. There is the v3.0.0.M1 release available now.Violaceous
V
53

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<Facebook> connection = facebookConnectionFactory.createConnection(accessGrant);
Facebook facebook = connection.getApi();
User userProfile = facebook.userOperations().getUserProfile();//raises the exception caused by the "bio" field.

AFTER

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

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"}
Violaceous answered 6/10, 2016 at 17:30 Comment(5)
I'm getting following error for above, any suggestions? {"errors":["com.fasterxml.jackson.databind.JsonMappingException","Can not construct instance of org.springframework.social.connect.UserProfile: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)\n at [Source: java.io.ByteArrayInputStream@fa18e2e; line: 1, column: 2]"]}Practically
This solution is a great replacement for facebook.userOperations().getUserProfile() method without any parameter. But how to do the same thing when we want to fetch user object for some other profile id? For example, how to do the same thing for facebook.userOperations().getUserProfile("some_facebook_id_here")Shallop
See https://mcmap.net/q/445624/-error-message-is-12-bio-field-is-deprecated-for-versions-v2-8-and-higher for another approach to this issue which will work in all scenarios.Shallop
I don't get it - where is this code you're showing supposed to go? I'm following the docs and I'm getting the same error - but where do you make this particular change in your code?Trudey
You can find the spring-social-facebook current docs here. In the 3.1 section there is the code that raises the error if you use 2.0.3.RELEASE of spring-social-facebook and facebook app api version >=v2.8.Violaceous
S
29

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.

Semi answered 28/10, 2016 at 19:38 Comment(1)
looks like my code is getting copied all over the internet :) https://mcmap.net/q/453893/-spring-social-facebook-login-error-numeric-value-out-of-range-of-intMohamedmohammad
T
11

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

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

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

<repositories>
    <repository>
        <id>alfresco-public</id>
        <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
    </repository>
</repositories>
Transmigrate answered 12/12, 2016 at 10:39 Comment(3)
Thanks for this...How about the Event operations? Would you have any knowledge. org.springframework.social.UncategorizedApiException: (#12) is_date_only field is deprecated for versions v2.4 and higher]Selfanalysis
This no longer works for me. I had to use the spring milestone repository:Bedmate
See this post for additional dependencies needed to get ConnectionRepository again with 3.0.0.M1 https://mcmap.net/q/453894/-what-has-happened-with-the-class-org-springframework-social-connect-connectionrepository-in-spring-social-3-0-0-m1Scharf
T
7
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";
    }

}
Thong answered 28/11, 2016 at 7:32 Comment(1)
How did you get those field data back? I only can get the name, first name and last name, anything else is null. I especially need to have friend data back. So, it is null as well.Retrieve
S
5

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

Selfexistent answered 2/7, 2017 at 16:14 Comment(1)
Super! This works perfectly fine. And I think this should be the appropriate answer to this question as this not only fixes the issue only for one scenario of facebook.userOperations().getUserProfile() but all other issues due to the bio field being discontinued. Thanks for the solution!Shallop
C
1

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.

Crackpot answered 11/3, 2017 at 21:23 Comment(0)
W
0
FacebookTemplate template = new FacebookTemplate(access_token); 
String [] fields = { "id", "email",  "first_name", "last_name" };
User profile = template.fetchObject("me", User.class, fields);
Walkling answered 28/4, 2017 at 7:50 Comment(0)
S
0

I copied interface UserOperations in my project changing PROFILE_FIELDS removing bio field. On Tomcat, my edited class takes priority over org.springframework.social.facebook.api.UserOperations interface and this fix the problem. (see last rows of below file)

/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.facebook.api;

import java.util.List;

import org.springframework.social.ApiException;
import org.springframework.social.MissingAuthorizationException;
public interface UserOperations {

/**
 * Retrieves the profile for the authenticated user.
 * @return the user's profile information.
 * @throws ApiException if there is an error while communicating with Facebook.
 * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
 */
User getUserProfile();

/**
 * Retrieves the profile for the specified user.
 * @param userId the Facebook user ID to retrieve profile data for.
 * @return the user's profile information.
 * @throws ApiException if there is an error while communicating with Facebook.
 */
User getUserProfile(String userId);

/**
 * Retrieves the user's profile image. Returns the image in Facebook's "normal" type.
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
 */
byte[] getUserProfileImage();

/**
 * Retrieves the user's profile image. Returns the image in Facebook's "normal" type.
 * @param userId the Facebook user ID.
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 */
byte[] getUserProfileImage(String userId);

/**
 * Retrieves the user's profile image.
 * @param imageType the image type (eg., small, normal, large. square)
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
 */
byte[] getUserProfileImage(ImageType imageType);

/**
 * Retrieves the user's profile image.
 * @param userId the Facebook user ID.
 * @param imageType the image type (eg., small, normal, large. square)
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 */
byte[] getUserProfileImage(String userId, ImageType imageType);

/**
 * Retrieves the user's profile image. When height and width are both used,
 * the image will be scaled as close to the dimensions as possible and then
 * cropped down.
 * @param width the desired image width
 * @param height the desired image height
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 */
byte[] getUserProfileImage(Integer width, Integer height);

/**
 * Retrieves the user's profile image. When height and width are both used,
 * the image will be scaled as close to the dimensions as possible and then
 * cropped down.
 * @param userId the Facebook user ID.
 * @param width the desired image width
 * @param height the desired image height
 * @return an array of bytes containing the user's profile image.
 * @throws ApiException if there is an error while communicating with Facebook.
 */
byte[] getUserProfileImage(String userId, Integer width, Integer height);

/**
 * Retrieves a list of permissions that the application has been granted for the authenticated user.
 * @return the permissions granted for the user.
 * @throws ApiException if there is an error while communicating with Facebook.
 * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
 */
List<Permission> getUserPermissions();

/**
 * Fetches IDs that the user has on any applications associated with the calling application via Facebook's Business Mapping API.
 * @return a list of ID-to-application mapping that the user has on related applications.
 */
List<UserIdForApp> getIdsForBusiness();

/**
 * Fetches a list of places that the user has checked into or has been tagged at.
 * @return a list of place tags for the user.
 */
List<PlaceTag> getTaggedPlaces();

/**
 * Searches for users.
 * @param query the search query (e.g., "Michael Scott")
 * @return a list of {@link Reference}s, each representing a user who matched the given query.
 * @throws ApiException if there is an error while communicating with Facebook.
 * @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
 */
PagedList<Reference> search(String query);

static final String[] PROFILE_FIELDS = {
    "id", "about", "age_range",/*"bio",*/ "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"
};

}

Shepard answered 23/3, 2018 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.