0

I need to shedule a facebook post using an image. It should appear in the planner tool of the Meta Business Suite.

I found this example, but I can't figure out how to use an image and set a publication date.

Depencency:

    <dependency>
        <groupId>com.facebook.business.sdk</groupId>
        <artifactId>facebook-java-business-sdk</artifactId>
        <version>17.0.3</version>
    </dependency>

Code:

import com.facebook.ads.sdk.*;
import java.io.File;
import java.util.Arrays;

public class PageFeedPost {
    public static void main (String args[]) throws APIException {

        // https://github.com/facebook/facebook-java-business-sdk/blob/main/examples/PageFeedPost.java

        String access_token = "<ACCESS_TOKEN>";
        String app_secret = "<APP_SECRET>";
        String app_id = "<APP_ID>";
        String id = "<PAGE_ID>";
        APIContext context = new APIContext(access_token).enableDebug(true);

        new Page(id, context).createFeed()
            .setMessage("This is a test value")
            .execute();

    }
}

Also, how to get all scheduled items from the planner?

1 Answer 1

0

The API documentation provides details about how to publish photos: https://developers.facebook.com/docs/pages/publishing#publish-a-photo

Accordingly, the JAVA SDK provides a method public APIRequestCreatePhoto createPhoto(), which you should use instead of createFeed().

Similarly, the API explains how to schedule a post: https://developers.facebook.com/docs/pages/publishing#schedule-a-page-post

  • you have to set published to false, which can be achieved using methodAPIRequestCreatePhoto.setPublished and
  • you need to set the schedule_publish_time parameter using method APIRequestCreatePhoto.setScheduledPublishTime

Edit: Retrieving scheduled posts is possible using method public APIRequestGetScheduledPosts getScheduledPosts() of class Page (https://developers.facebook.com/docs/graph-api/reference/page/scheduled_posts/).

2
  • Thank you. This is very helpful. The createPhoto doesn't have a ".addUploadFile" methode. Do you know how to upload a photo? Commented Aug 21, 2023 at 14:38
  • You can have a look at the graph API reference for photos (developers.facebook.com/docs/graph-api/reference/photo) to find out, which fields exist at the endpoint. You have to specify a URL of the photo. The SDK provides method APIRequestCreatePhoto.setUrl
    – me.
    Commented Aug 21, 2023 at 21:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.