Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Expose endpoint for accessing Profile URL instead of bytes and Flexibility on Comments, Posts and Likes #228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.social.ApiException;
import org.springframework.social.InsufficientPermissionException;
import org.springframework.social.MissingAuthorizationException;
import org.springframework.util.MultiValueMap;


/**
Expand All @@ -43,6 +44,15 @@ public interface CommentOperations {
*/
PagedList<Comment> getComments(String objectId, PagingParameters pagedListParameters);

/**
* Retrieves comments for a given object.
* @param objectId the ID of the object
* @param params the parameters defining the bounds of the list to return.
* @return a list of {@link Comment}s for the specified object
* @throws ApiException if there is an error while communicating with Facebook.
*/
PagedList<Comment> getComments(String objectId, MultiValueMap<String, String> params);

/**
* Retrieves a single comment
* @param commentId the comment ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.social.InsufficientPermissionException;
import org.springframework.social.MissingAuthorizationException;
import org.springframework.social.RateLimitExceededException;
import org.springframework.util.MultiValueMap;

/**
* Interface defining operations that can be performed on a Facebook feed.
Expand Down Expand Up @@ -99,6 +100,23 @@ public interface FeedOperations {
* @throws ApiException if there is an error while communicating with Facebook.
*/
Post getPost(String entryId);

/**
* Retrieve a single post with meta data
* @param entryId the entry ID
* @return the requested {@link Post}
* @throws ApiException if there is an error while communicating with Facebook.
*/
Post getPostWithMeta(String entryId);

/**
* Retrieve a single post with meta data
* @param entryId the entry ID
* @param params the extended URI paramas
* @return the requested {@link Post}
* @throws ApiException if there is an error while communicating with Facebook.
*/
Post getPostWithMeta(String entryId, MultiValueMap<String, String> params);

/**
* Retrieves the status entries from the authenticated user's feed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public interface GraphApi {
*/
byte[] fetchImage(String objectId, String connectionName, Integer width, Integer height);

/**
* Fetch the image url instead of the actual bytes
* @param objectId the object ID
* @param width desired width of the image (optional)
* @param height desired height of the image (optional)
* @return a URL of the image
*/
String fetchImageUrl(String objectId, Integer width, Integer height);

/**
* Publishes data to an object's connection.
* Requires appropriate permission to publish to the object connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.social.ApiException;
import org.springframework.social.InsufficientPermissionException;
import org.springframework.social.MissingAuthorizationException;
import org.springframework.util.MultiValueMap;


/**
Expand Down Expand Up @@ -47,6 +48,16 @@ public interface LikeOperations {
*/
PagedList<Reference> getLikes(String objectId, PagingParameters pagingParameters);

/**
* Retrieves a page of references to users who have liked the specified object.
* @param objectId the object ID (an Album, Checkin, Comment, Note, Photo, Post, or Video).
* @param params the paging parameters for fetching a specific page of references.
* @return a list of {@link Reference} objects for the users who have liked the object.
* @throws ApiException if there is an error while communicating with Facebook.
* @throws MissingAuthorizationException if FacebookTemplate was not created with an access token.
*/
PagedList<Reference> getLikes(String objectId, MultiValueMap<String, String> params);

/**
* Retrieves a list of pages that the authenticated user has liked.
* Requires "user_likes" permission. Returns an empty list if permission isn't granted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public interface UserOperations {
*/
byte[] getUserProfileImage(String userId, ImageType imageType);

/**
* Get the user profile image url
* @param userId the facebook user ID
* @param width desired width of image (optional)
* @param height desired height of image (optional)
* @return Url of profile image
*/
String getUserProfileImageUrl(String userId, Integer width, Integer height);

/**
* Retrieves the user's profile image. When height and width are both used,
* the image will be scaled as close to the dimensions as possible and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public PagedList<Comment> getComments(String objectId, PagingParameters pagedLis
return graphApi.fetchConnections(objectId, "comments", Comment.class, getPagingParameters(pagedListParameters));
}

public PagedList<Comment> getComments(String objectId, MultiValueMap<String, String> params) {
return graphApi.fetchConnections(objectId, "comments", Comment.class, params);
}

public Comment getComment(String commentId) {
return graphApi.fetchObject(commentId, Comment.class, ALL_FIELDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ public byte[] fetchImage(String objectId, String connectionType, Integer width,
return fetchImage(objectId, connectionType, null, width, height);
}

public String fetchImageUrl(String objectId, Integer width, Integer height) {
URIBuilder uriBuilder = URIBuilder.fromUri(getBaseGraphApiUrl() + objectId + "/picture");
if (width != null) {
uriBuilder.queryParam("width", width.toString());
}
if (height != null) {
uriBuilder.queryParam("height", height.toString());
}
try {
JsonNode response = getRestTemplate().getForObject(uriBuilder.build(), JsonNode.class);
return response.get("data").get("url").asText();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private byte[] fetchImage(String objectId, String connectionType, ImageType type, Integer width, Integer height) {
URIBuilder uriBuilder = URIBuilder.fromUri(getBaseGraphApiUrl() + objectId + "/" + connectionType);
if (type != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ public Post getPost(String entryId) {
return deserializePost(null, Post.class, responseNode);
}

public Post getPostWithMeta(String entryId) {
ObjectNode responseNode = (ObjectNode) restTemplate.getForObject(graphApi.getBaseGraphApiUrl() + entryId + "?metadata=true", JsonNode.class);
return deserializePost(null, Post.class, responseNode);
}

public Post getPostWithMeta(String entryId, MultiValueMap<String, String> queryParameters) {
URIBuilder uriBuilder = URIBuilder.fromUri(graphApi.getBaseGraphApiUrl() + entryId).queryParams(queryParameters);
ObjectNode responseNode = (ObjectNode) restTemplate.getForObject(uriBuilder.build(), JsonNode.class);
return deserializePost(null, Post.class, responseNode);
}

public String updateStatus(String message) {
return post("me", message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.springframework.social.facebook.api.PagingParameters;
import org.springframework.social.facebook.api.Reference;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.Map;

class LikeTemplate implements LikeOperations {

Expand All @@ -47,6 +50,10 @@ public PagedList<Reference> getLikes(String objectId, PagingParameters pagingPar
return graphApi.fetchConnections(objectId, "likes", Reference.class, pagingParameters.toMap());
}

public PagedList<Reference> getLikes(String objectId, MultiValueMap<String, String> params) {
return graphApi.fetchConnections(objectId, "likes", Reference.class, params);
}

public PagedList<Page> getPagesLiked() {
return getPagesLiked("me");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public byte[] getUserProfileImage(String userId) {
return getUserProfileImage(userId, ImageType.NORMAL);
}

public String getUserProfileImageUrl(String userId) { return getUserProfileImageUrl(userId, null, null);}

public byte[] getUserProfileImage(ImageType imageType) {
return getUserProfileImage("me", imageType);
}
Expand All @@ -69,6 +71,10 @@ public byte[] getUserProfileImage(String userId, ImageType imageType) {
return graphApi.fetchImage(userId, "picture", imageType);
}

public String getUserProfileImageUrl(String userId, Integer width, Integer height) {
return graphApi.fetchImageUrl(userId, width, height);
}

public byte[] getUserProfileImage(Integer width, Integer height) {
return getUserProfileImage("me", width, height);
}
Expand Down