Подтвердить что ты не робот

Сообщение об ошибке (# 12) bio field устарело для версий v2.8 и выше

Я использовал версию 2.0.3.RELEASE из spring -социально-facebook и Facebook app api v2.8. Я позвонил в Facebook, но вернул это сообщение. "(# 12) bio field устарел для версий v2.8 и выше" Как я могу это исправить?

4b9b3361

Ответ 1

У меня такая же ошибка, 2.0.3.RELEASE из spring -social-facebook, похоже, несовместим с версией Facebook API версии v2.8 (выпущен вчера). Чтение из журнала изменений в 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) в константе PROFILE_FIELDS есть поле "bio", и оно не поддерживается в версии API v2.8 facebook.

ОБНОВЛЕНИЕ: я нашел обходной путь в моем случае:

ДО:

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

Ответ 2

Обходной путь для 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();
    }
}

Источник: https://github.com/jhipster/generator-jhipster/issues/2349 - минус bio в массиве fieldsToMap.

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

}

Ответ 4

Это было исправлено в новой версии 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>

Ответ 5

Под grails spring security facebook у меня была аналогичная проблема и благодаря @user6904265 Мне удалось заставить его работать:

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

В основном по умолчанию приведен пример выше состояний User.class. Локальному запуску не удалось найти такие поля, как last_name и т.д., И дал список, который он мог запросить. Эти предоставленные опции были из фактического класса безопасности spring для пользователя (по умолчанию для моего приложения), поэтому убедитесь, что вы также просматриваете правильные классы пользователей.

Ответ 6

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

Ответ 7

У меня возникли проблемы с новой версией 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.

Здесь вы можете увидеть более подробную информацию: https://github.com/jhipster/generator-jhipster/issues/2349

Ответ 8

удалите параметр → "bio" из своего URL-адреса вызова api, для меня он решил

перед тем                 " 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="

после

" 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="