web-dev-qa-db-fra.com

Le message d'erreur est (# 12) le champ bio est obsolète pour les versions v2.8 et supérieures.

J'ai utilisé la version 2.0.3.RELEASE de spring-social-facebook et de l'application Facebook api v2.8 . J'ai appelé le login Facebook mais j'ai renvoyé ce message . "(# 12) le champ bio est obsolète pour les versions v2. 8 et plus " Comment puis-je résoudre ce problème?

29
Anselm Kim

J'ai la même erreur, 2.0.3.RELEASE de spring-social-facebook ne semble pas être compatible avec la version v2.8 de l'API Facebook (publiée hier). Lecture sur Facebook changelog pour la v2.8 ( https://developers.facebook.com/docs/apps/changelog ):

User Bios - Le champ bio de l'objet Utilisateur n'est plus disponible. Si le champ bio a été défini pour une personne, la valeur sera maintenant ajoutée au champ about.

Je pense que nous devons attendre une nouvelle version de la bibliothèque Spring-social-facebook. La version 2.0.3 (dans l'interface org.springframework.social.facebook.api.UserOperations) contient le champ "bio" dans la constante PROFILE_FIELDS et n'est pas pris en charge dans la version v2.8 de l'API facebook.

MISE À JOUR: j'ai trouvé une solution de contournement dans mon cas:

AVANT:

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

APRÈS

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

Voici une liste complète des champs que vous pouvez utiliser:

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

Solution de contournement pour JHipster . Ajoutez l'extrait de code suivant dans votre classe SocialService jusqu'à ce que spring-social-facebook soit corrigé.

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 - moins bio dans le tableau fieldsToMap.

29
Michal Foksa

Ce problème a été résolu dans la nouvelle version de spring-social-facebook. S'il vous plaît ajouter ce qui suit à votre pom.xml

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

Si vous obtenez une erreur indiquant que cette version n'est pas disponible, ajoutez également les éléments suivants.

<repositories>
    <repository>
        <id>alfresco-public</id>
        <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
    </repository>
</repositories>
11
Heisenberg
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";
    }

}
8
Vasundhara

J'ai eu des problèmes avec la nouvelle version de spring-social-facebook. Pour résoudre ce problème à l'aide de la version 2.0.3.RELEASE, collez le code suivant dans votre 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();
    }
}

Ce code n'essaiera pas de récupérer le champ bio de Facebook.

Vous pouvez voir plus de détails ici: https://github.com/jhipster/generator-jhipster/issues/2349

5
joalcego

Sous Grails Spring, j'ai eu un problème similaire sur Facebook et Grâce à @ user6904265, j'ai réussi à le faire fonctionner:

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

L'exemple ci-dessus fourni par défaut ci-dessus indique User.class. Cette exécution locale n'a pas pu trouver de champs tels que nom_de_nom etc. et a donné une liste pouvant être interrogée. Ces options fournies provenaient de la classe d'utilisateurs de sécurité de printemps réelle (par défaut pour mon application), alors assurez-vous également de rechercher les classes d'utilisateurs appropriées.

1
Vahid
FacebookTemplate template = new FacebookTemplate(access_token); 
String [] fields = { "id", "email",  "first_name", "last_name" };
User profile = template.fetchObject("me", User.class, fields);
0
Ishin Vin
0
Wesley S Favarin

J'ai copié l'interface UserOperations dans mon projet en changeant PROFILE_FIELDS enlevant bio champ. Sur Tomcat, ma classe modifiée a la priorité sur l'interface org.springframework.social.facebook.api.UserOperations et corrige le problème. (voir les dernières lignes du fichier ci-dessous)

/*
 * 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"
};

}

0
fciri