gpt4 book ai didi

Spring social facebook 登录错误 - 数值超出 int 范围

转载 作者:行者123 更新时间:2023-11-30 05:19:33 27 4
gpt4 key购买 nike

我在使用 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 依赖项:

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)

代码:

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

这个完整的异常:

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

最佳答案

更新

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

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

旧答案

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

使用以下代码:

@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 方法。

Issue on github

关于Spring social facebook 登录错误 - 数值超出 int 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com