I am using Facebook graph API
Facebook graph API, to update my Instagram page's post create/ update.
the endpoint I am using is like
https://graph.facebook.com/{media_id}?caption={new_caption}&access_token={access_token}
Neither using insomnia
nor using JAVA
code do I receive the successful message, and the caption remains unchanged.
private static CompletableFuture<PostFB> updatePostInstagramMessageAsync(String hostname, PostFB ig, HttpClient client) {
JSONObject jsonPayload = new JSONObject();
if (ig.text != null && !ig.text.isEmpty()) {
jsonPayload.put("caption", ig.text);
jsonPayload.put("comment_enabled", true);
System.out.println("jsonPayload is " + jsonPayload.toString());
String url = "https://graph.facebook.com/v19.0/" + "my postID";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url + "?access_token=" + ig.page_access_token))
.header("Content-Type", "application/json")
.method("POST", BodyPublishers.ofString(jsonPayload.toString(), StandardCharsets.UTF_8))
.build();
return client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(response -> {
System.out.println("Response for updating post is " + response.body());
if (response.statusCode() == 200) {
System.out.println("Updated post successfully.");
} else {
System.out.println("Failed to update post: " + response.body());
}
} else {
System.out.println("Failed to update post. Status code: " + response.statusCode());
}
return ig;
})
.exceptionally(ex -> {
ex.printStackTrace();
return ig;
});
} else {
return CompletableFuture.completedFuture(null);
}
}
Despite receiving a successful response, the caption does not change. I have created the application and assigned the necessary permissions:
I am able to create new posts but I cannot modify them. Why? any help would be appriciated.
https://developers.facebook.com/docs/instagram-api/reference/ig-media#updating
Updating
POST /{ig-media-id}Enable or disable comments on an IG Media.
What that last line says, is the only thing you can do via this update endpoint.
You get a success response, because you successfully set or changed the value of comment_enabled
.
The additional parameter caption
you are passing, has no meaning for this endpoint, and simply gets ignored.