Closed confile closed 11 years ago
You might try something like this (code not tested):
boolean liked = false
FacebookGraphClient facebookGraphClient = new FacebookGraphClient(pageOrUserToken)
try {
liked = facebookGraphClient.makePostRequest("${postFacebookId}/likes").toBoolean()
} catch (FacebookException exception) {
log.warn(exception)
}
And to unlike:
FacebookGraphClient facebookGraphClient = new FacebookGraphClient(pageOrUserToken)
try {
facebookGraphClient.makeDeleteRequest("${postFacebookId}/likes")
} catch (FacebookException exception) {
log.warn(exception)
}
@benorama What is the variable postFacebookId? Where do I get this? Or is it always "me" as String?
postFacebookId is the facebook ID of the post or the comment. A like can only be published on a post or a comment, you can't "publish a like on a user timeline".
/me will return the current object depending on the token you are using : a user or a page. You can get the /me/feed connection to list all the posts and comments but you can also use another page or user id to see its public feed: /${userFacebookId}/feed or /${pageFacebookId}/feed . In this feed, you can get post Facebook IDs or comment Facebook IDs in order to perform like requests.
You might want to do some experimentation with the Facebook Graph Explorer, to manually discover and test all the Facebook Graph APIs before trying to use them with Grails: http://developers.facebook.com/tools/explorer. It's a great learning tool.
How can I use facebookClient.publish to publish a like on users wall?
Is there something like: facebookClient.publish("me/like",....?