Facebook graph api Spring社交Facebook |从feedOperations获得大照片
当我执行下面的代码时,我得到的只是一个小图片Facebook graph api Spring社交Facebook |从feedOperations获得大照片,facebook-graph-api,spring-social,spring-social-facebook,Facebook Graph Api,Spring Social,Spring Social Facebook,当我执行下面的代码时,我得到的只是一个小图片 PagingParameters recordCount = new PagingParameters(2000, null, null, null); PagedList<Post> posts = facebook.feedOperations().getPosts(recordCount); PagingParameters recordCount=新的PagingParameters(2000,null,null,null);
PagingParameters recordCount = new PagingParameters(2000, null, null, null);
PagedList<Post> posts = facebook.feedOperations().getPosts(recordCount);
PagingParameters recordCount=新的PagingParameters(2000,null,null,null);
PagedList posts=facebook.feedOperations().getPosts(recordCount);
Maven版本:
<dependency
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId> <version>2.0.3.RELEASE</version>
</dependency>
我为这个问题分析了很多并发布了解决方案,因为其他人可以从中获得帮助。它返回完整图片作为post额外数据的一部分,可以使用post.getExtraData().get(“完整图片”)获取这些数据。代码快照如下所示
public PagedList<Post> getPostByAccountId(final String accountId) {
LOGGER.debug("facebook accountId: ", accountId);
FacebookTemplate facebook = new FacebookTemplate("<access token>");
String[] ALL_POST_FIELDS = { "id", "actions", "admin_creator", "application", "caption", "created_time", "description", "from", "icon", "is_hidden", "is_published",
"link", "message", "message_tags", "name", "object_id", "picture", "full_picture", "place", "privacy", "properties", "source", "status_type", "story", "to",
"type", "updated_time", "with_tags", "shares" };
URIBuilder uriBuilder = URIBuilder.fromUri(facebook.getBaseGraphApiUrl() + "me/posts");
uriBuilder = uriBuilder.queryParam("limit", String.valueOf(2000));
uriBuilder.queryParam("fields", org.springframework.util.StringUtils.arrayToCommaDelimitedString(ALL_POST_FIELDS));
URI uri = uriBuilder.build();
JsonNode jsonNode = (JsonNode) facebook.getRestTemplate().getForObject(uri, JsonNode.class);
PagedList<Post> posts = new DeserializingPosts().deserializeList(jsonNode, null, Post.class);
return posts;
}
反序列化对象类详细信息:
public class DeserializingPosts extends AbstractOAuth2ApiBinding {
private ObjectMapper objectMapper = new ObjectMapper();
/**
*
* @param jsonNode
* @param postType
* @param type
* @return
*/
public <T> PagedList<T> deserializeList(JsonNode jsonNode, String postType, Class<T> type) {
JsonNode dataNode = jsonNode.get("data");
List posts = new ArrayList();
for (Iterator iterator = dataNode.iterator(); iterator.hasNext();) {
posts.add(deserializePost(postType, type, (ObjectNode) iterator.next()));
}
if (jsonNode.has("paging")) {
JsonNode pagingNode = jsonNode.get("paging");
PagingParameters previousPage = PagedListUtils.getPagedListParameters(pagingNode, "previous");
PagingParameters nextPage = PagedListUtils.getPagedListParameters(pagingNode, "next");
return new PagedList(posts, previousPage, nextPage);
}
return new PagedList(posts, null, null);
}
/**
*
* @param postType
* @param type
* @param node
* @return
*/
public <T> T deserializePost(String postType, Class<T> type, ObjectNode node) {
try {
if (postType == null) {
postType = determinePostType(node);
}
node.put("postType", postType);
node.put("type", postType);
MappingJackson2HttpMessageConverter converter = super.getJsonMessageConverter();
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new FacebookModule());
converter.setObjectMapper(this.objectMapper);
return this.objectMapper.reader(type).readValue(node.toString());
} catch (IOException shouldntHappen) {
throw new UncategorizedApiException("facebook", "Error deserializing " + postType + " post", shouldntHappen);
}
}
/**
*
* @param node
* @return
*/
private String determinePostType(ObjectNode node) {
if (node.has("type")) {
try {
String type = node.get("type").textValue();
Post.PostType.valueOf(type.toUpperCase());
return type;
} catch (IllegalArgumentException e) {
return "post";
}
}
return "post";
}
公共类反序列化Posts扩展了AbstractOAuth2ApiBinding{
私有ObjectMapper ObjectMapper=新ObjectMapper();
/**
*
*@param jsonNode
*@param postType
*@param类型
*@返回
*/
公共页面列表反序列化列表(JsonNode JsonNode,字符串postType,类类型){
JsonNode dataNode=JsonNode.get(“数据”);
List posts=new ArrayList();
for(Iterator Iterator=dataNode.Iterator();Iterator.hasNext();){
add(反序列化post(postType,type,(ObjectNode)iterator.next());
}
if(jsonNode.has(“分页”)){
JsonNode pagingNode=JsonNode.get(“分页”);
PagingParameters previousPage=PagedListIls.getPagedListParameters(pagingNode,“previous”);
PagingParameters nextPage=PagedListTils.getPagedListParameters(pagingNode,“下一步”);
返回新的页面列表(帖子、上一页、下一页);
}
返回新的页面列表(posts、null、null);
}
/**
*
*@param postType
*@param类型
*@param节点
*@返回
*/
公共T反序列化Post(字符串postType、类类型、ObjectNode){
试一试{
if(postType==null){
postType=determinePostType(节点);
}
node.put(“postType”,postType);
node.put(“type”,postType);
MappingJackson2HttpMessageConverter=super.getJsonMessageConverter();
this.objectMapper=新的objectMapper();
这个.objectMapper.registerModule(新的FacebookModule());
setObjectMapper(this.objectMapper);
返回此.objectMapper.reader(type).readValue(node.toString());
}捕获(IOException shouldntHappen){
抛出新的UncategorizedApiException(“facebook”,“错误反序列化”+postType+“post”,shouldntHappen);
}
}
/**
*
*@param节点
*@返回
*/
私有字符串determinePostType(ObjectNode节点){
if(node.has(“type”)){
试一试{
字符串类型=node.get(“type”).textValue();
Post.PostType.valueOf(type.toUpperCase());
返回类型;
}捕获(IllegalArgumentException e){
返回“post”;
}
}
返回“post”;
}
}我为这个问题分析了很多并发布了解决方案,因为其他人可以从中获得帮助。它返回完整图片作为post额外数据的一部分,可以使用post.getExtraData().get(“完整图片”)获取这些数据。代码快照如下所示
public PagedList<Post> getPostByAccountId(final String accountId) {
LOGGER.debug("facebook accountId: ", accountId);
FacebookTemplate facebook = new FacebookTemplate("<access token>");
String[] ALL_POST_FIELDS = { "id", "actions", "admin_creator", "application", "caption", "created_time", "description", "from", "icon", "is_hidden", "is_published",
"link", "message", "message_tags", "name", "object_id", "picture", "full_picture", "place", "privacy", "properties", "source", "status_type", "story", "to",
"type", "updated_time", "with_tags", "shares" };
URIBuilder uriBuilder = URIBuilder.fromUri(facebook.getBaseGraphApiUrl() + "me/posts");
uriBuilder = uriBuilder.queryParam("limit", String.valueOf(2000));
uriBuilder.queryParam("fields", org.springframework.util.StringUtils.arrayToCommaDelimitedString(ALL_POST_FIELDS));
URI uri = uriBuilder.build();
JsonNode jsonNode = (JsonNode) facebook.getRestTemplate().getForObject(uri, JsonNode.class);
PagedList<Post> posts = new DeserializingPosts().deserializeList(jsonNode, null, Post.class);
return posts;
}
反序列化对象类详细信息:
public class DeserializingPosts extends AbstractOAuth2ApiBinding {
private ObjectMapper objectMapper = new ObjectMapper();
/**
*
* @param jsonNode
* @param postType
* @param type
* @return
*/
public <T> PagedList<T> deserializeList(JsonNode jsonNode, String postType, Class<T> type) {
JsonNode dataNode = jsonNode.get("data");
List posts = new ArrayList();
for (Iterator iterator = dataNode.iterator(); iterator.hasNext();) {
posts.add(deserializePost(postType, type, (ObjectNode) iterator.next()));
}
if (jsonNode.has("paging")) {
JsonNode pagingNode = jsonNode.get("paging");
PagingParameters previousPage = PagedListUtils.getPagedListParameters(pagingNode, "previous");
PagingParameters nextPage = PagedListUtils.getPagedListParameters(pagingNode, "next");
return new PagedList(posts, previousPage, nextPage);
}
return new PagedList(posts, null, null);
}
/**
*
* @param postType
* @param type
* @param node
* @return
*/
public <T> T deserializePost(String postType, Class<T> type, ObjectNode node) {
try {
if (postType == null) {
postType = determinePostType(node);
}
node.put("postType", postType);
node.put("type", postType);
MappingJackson2HttpMessageConverter converter = super.getJsonMessageConverter();
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new FacebookModule());
converter.setObjectMapper(this.objectMapper);
return this.objectMapper.reader(type).readValue(node.toString());
} catch (IOException shouldntHappen) {
throw new UncategorizedApiException("facebook", "Error deserializing " + postType + " post", shouldntHappen);
}
}
/**
*
* @param node
* @return
*/
private String determinePostType(ObjectNode node) {
if (node.has("type")) {
try {
String type = node.get("type").textValue();
Post.PostType.valueOf(type.toUpperCase());
return type;
} catch (IllegalArgumentException e) {
return "post";
}
}
return "post";
}
公共类反序列化Posts扩展了AbstractOAuth2ApiBinding{
私有ObjectMapper ObjectMapper=新ObjectMapper();
/**
*
*@param jsonNode
*@param postType
*@param类型
*@返回
*/
公共页面列表反序列化列表(JsonNode JsonNode,字符串postType,类类型){
JsonNode dataNode=JsonNode.get(“数据”);
List posts=new ArrayList();
for(Iterator Iterator=dataNode.Iterator();Iterator.hasNext();){
add(反序列化post(postType,type,(ObjectNode)iterator.next());
}
if(jsonNode.has(“分页”)){
JsonNode pagingNode=JsonNode.get(“分页”);
PagingParameters previousPage=PagedListIls.getPagedListParameters(pagingNode,“previous”);
PagingParameters nextPage=PagedListTils.getPagedListParameters(pagingNode,“下一步”);
返回新的页面列表(帖子、上一页、下一页);
}
返回新的页面列表(posts、null、null);
}
/**
*
*@param postType
*@param类型
*@param节点
*@返回
*/
公共T反序列化Post(字符串postType、类类型、ObjectNode){
试一试{
if(postType==null){
postType=determinePostType(节点);
}
node.put(“postType”,postType);
node.put(“type”,postType);
MappingJackson2HttpMessageConverter=super.getJsonMessageConverter();
this.objectMapper=新的objectMapper();
这个.objectMapper.registerModule(新的FacebookModule());
setObjectMapper(this.objectMapper);
返回此.objectMapper.reader(type).readValue(node.toString());
}捕获(IOException shouldntHappen){
抛出新的UncategorizedApiException(“facebook”,“错误反序列化”+postType+“post”,shouldntHappen);
}
}
/**
*
*@param节点
*@返回
*/
私有字符串determinePostType(ObjectNode节点){
if(node.has(“type”)){
试一试{
字符串类型=node.get(“type”).textValue();
Post.PostType.valueOf(type.toUpperCase());
返回类型;
}捕获(IllegalArgumentException e){
返回“post”;
}
}
返回“post”;
}
}Spring社交Facebook |从用户帖子或页面获取全貌。Spring社交Facebook |从用户帖子或页面获取全貌。