当前位置:  开发笔记 > 开放平台 > 正文

Spring社交facebook登录错误 - 数字值超出int范围

如何解决《Spring社交facebook登录错误-数字值超出int范围》经验,为你挑选了1个好方法。

我使用Spring Social时遇到问题,当我尝试登录Facebook时,出现以下错误:

org.springframework.social.facebook.api.User["video_upload_limits"]->org.springframework.social.facebook.api.VideoUploadLimits["size"])

com.fasterxml.jackson.databind.JsonMappingException: Numeric value (2505397589) out of range of int

在此先感谢您的帮助.

maven依赖:

春季4.2.0.RELEASE

    
    
        org.springframework.social
        spring-social-core
        1.1.2.RELEASE
    

    
        org.springframework.social
        spring-social-web
        1.1.2.RELEASE
    

    
        org.springframework.social
        spring-social-facebook
        2.0.1.RELEASE
    

    
    
        com.fasterxml.jackson.core
        jackson-core
        2.6.2
    
    
        com.fasterxml.jackson.core
        jackson-databind
        2.6.2
    
    
        com.fasterxml.jackson.core
        jackson-annotations
        2.6.2
    

    ==> same error when version up to 2.7.0-rc1(jackson)

代码:

String authorizationCode = request.getParameter("code");

FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(this.appId, this.appSecret);

OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();

AccessGrant accessGrant = oauthOperations.exchangeForAccess(authorizationCode, RequestUtil.getRedirectionURLForSNSSignUp(request, provider), null);

// error line
Connection connection = connectionFactory.createConnection(accessGrant);

User user = connection.getApi().userOperations().getUserProfile();

这个完整的例外:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Numeric value (2505397589) out of range of int
 at [Source: java.io.ByteArrayInputStream@3de52269; line: 1, column: 4064] (through reference chain: org.springframework.social.facebook.api.User["video_upload_limits"]->org.springframework.social.facebook.api.VideoUploadLimits["size"])
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:224)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:208)
    at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:96)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:594)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:567)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:275)
    at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:214)
    at org.springframework.social.facebook.api.impl.FacebookTemplate.fetchObject(FacebookTemplate.java:209)
    at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:53)
    at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:49)
    at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:43)
    at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:31)
    at org.springframework.social.connect.support.AbstractConnection.setValues(AbstractConnection.java:175)
    at org.springframework.social.connect.support.AbstractConnection.initKey(AbstractConnection.java:137)
    at org.springframework.social.connect.support.OAuth2Connection.(OAuth2Connection.java:75)
    at org.springframework.social.connect.support.OAuth2ConnectionFactory.createConnection(OAuth2ConnectionFactory.java:93)

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Numeric value (2505397589) out of range of int
 at [Source: java.io.ByteArrayInputStream@3de52269; line: 1, column: 4064] (through reference chain: org.springframework.social.facebook.api.User["video_upload_limits"]->org.springframework.social.facebook.api.VideoUploadLimits["size"])
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
    at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1474)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:463)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:376)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1099)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:294)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:131)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:256)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3731)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2808)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:221)
    ... 78 more

Caused by: com.fasterxml.jackson.core.JsonParseException: Numeric value (2505397589) out of range of int
 at [Source: java.io.ByteArrayInputStream@3de52269; line: 1, column: 4064]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1581)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:533)
    at com.fasterxml.jackson.core.base.ParserBase.convertNumberToInt(ParserBase.java:890)
    at com.fasterxml.jackson.core.base.ParserBase._parseIntValue(ParserBase.java:828)
    at com.fasterxml.jackson.core.base.ParserBase.getIntValue(ParserBase.java:656)
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:307)
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$IntegerDeserializer.deserialize(NumberDeserializers.java:287)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:461)
    ... 89 more

kamwo.. 17

更新

它看起来像是spring-social-facebook已经创建的新版本,并且已经在github页面上可用.它应该很快就可以通过Maven获得.


    org.springframework.social
    spring-social-facebook
    2.0.3.RELEASE


老答案

只要没有库的更新,您也可以使用反射并从中删除"video_upload_limit" UserOperations.java.所以我们不需要扩展/重写任何代码或者必须编译我们自己的Spring Social Facebooklib 版本.

使用以下代码:

@PostConstruct
private void init() {
    // hack for the facebook login
    try {
        String[] fieldsToMap = {
                "id", "about", "age_range", "address", "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", "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();
    }
}

在我的例子中,我使用社交媒体的配置类,并在其中放置了带有此代码的@PostConstruct方法.

关于github的问题



1> kamwo..:

更新

它看起来像是spring-social-facebook已经创建的新版本,并且已经在github页面上可用.它应该很快就可以通过Maven获得.


    org.springframework.social
    spring-social-facebook
    2.0.3.RELEASE


老答案

只要没有库的更新,您也可以使用反射并从中删除"video_upload_limit" UserOperations.java.所以我们不需要扩展/重写任何代码或者必须编译我们自己的Spring Social Facebooklib 版本.

使用以下代码:

@PostConstruct
private void init() {
    // hack for the facebook login
    try {
        String[] fieldsToMap = {
                "id", "about", "age_range", "address", "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", "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();
    }
}

在我的例子中,我使用社交媒体的配置类,并在其中放置了带有此代码的@PostConstruct方法.

关于github的问题

推荐阅读
吻过彩虹的脸_378
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有