Spring social facebook login error - Numeric value out of range of int

隐身守侯 提交于 2019-12-17 21:01:52

问题


I have a problem using Spring Social, when I tried to login to Facebook, I get the following error:

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

Thanks in advance for any help.

maven dependencies:

Spring 4.2.0.RELEASE

    <!-- Spring Social -->
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-core</artifactId>
        <version>1.1.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-web</artifactId>
        <version>1.1.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-facebook</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>

    <!-- jason -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.6.2</version>
    </dependency>

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

Code :

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<Facebook> connection = connectionFactory.createConnection(accessGrant);

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

this full exception:

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.<init>(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

回答1:


Update

It looks like a new release of spring-social-facebook has been created and is available already on the github page. It should be available through Maven shortly.

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-facebook</artifactId>
    <version>2.0.3.RELEASE</version>
</dependency>

Old answer

As long as there is no update of the library, you can also just use reflections and remove the "video_upload_limit" from UserOperations.java. So we do not need to extend/rewrite any code or have to compile our own version of the Spring Social Facebook lib.

Use the following code:

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

In my case I use a configuration class for social media and I have placed a @PostConstruct method with this code in it.

Issue on github




回答2:


Looks like an issue with an update on facebooks side on Dec 6th 2015. I guess they allow larger video file uploads. There's a workaround described here until spring social is updated: https://github.com/spring-projects/spring-social-facebook/issues/181 (need to edit the class org.springframework.social.facebook.api.UserOperations.java, compile and put back in the spring-social-facebook-2.0.2.RELEASE.jar file).




回答3:


Graph Api documentation says integer, but size response with a long:

curl "https://graph.facebook.com/v2.5/me?fields=video_upload_limits&access_token=XXX"
{"video_upload_limits":{"length":3600,"size":2505397589},"id":"1089515813"}

Opened a bug ticket for facebook team to update the documentation: https://developers.facebook.com/bugs/1660757127499390/




回答4:


This snapshot works fine. Could be used as a temporary solution.

<repository>
  <id>Spring Snapshot</id>
  <url>http://repo.spring.io/simple/snapshot/</url>
  <releases>
    <enabled>false</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>


<dependency>
  <groupId>org.springframework.social</groupId>
  <artifactId>spring-social-facebook</artifactId>
  <version>2.0.3.BUILD-SNAPSHOT</version>
</dependency>


来源:https://stackoverflow.com/questions/34125425/spring-social-facebook-login-error-numeric-value-out-of-range-of-int

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