I'm trying to replicate the following request (which I elaborated with the Facebook graph explorer)
POST /{page_id}/subscribed_apps?subscribed_fields=feed,mention
with it's accompanying page access token. The response I get from that request is
{
"success": true
}
How do I make that same request using RestFB? So far I've managed to come up with:
FacebookClient client = new DefaultFacebookClient(pageAccessToken, Version.VERSION_8_0);
JsonObject result = client.publish(
String.format("/%s/%s", pageId, "subscribed_apps"),
JsonObject.class,
Parameter.with("subscribed_fields", "feed,mention"));
But all I get is:
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#100) Parameters do not match any fields that can be updated (code 100, subcode null) 'null - null'
To make this more easy and readable, I suggest you try this code:
FacebookClient client = ne DefaultFacebookClient(pageAccessToken, Version.LATEST);
GraphResponse result = client.publish("me/subscribed_apps",
GraphResponse.class,
Parameter.with("subscribed_fields","feed,mention"));
if (result.isSuccess()) {
// do some stuff
}
That way, you don't need the page id
and no String.format
. The page id is already connected to the page access token and sometimes this leads to better working results.
RestFB provides a special object for this kind of requests called GraphResponse
. It's a simple object that provides some convenience methods. As long as you don't get a complete object back, like a user or post, this is a better way ;)