5

I just had to do this. Absolutely every question I looked up questions regarding this issue but none of their answers helped me solve it.

I am trying to post on my Facebook page.

Here is the issue:

Error: "(#100) You cannot specify a scheduled publish time on a published post"

Code:

FB.api(
    "/100177680105780/feed",
    "POST",
    {

        "message": "This is a test message",
        "scheduled_publish_time": Math.round(new Date().getTime() / 1000) + 120

    },
    function (response) {
        console.log(response);
        if (response && !response.error) {
            /* handle the result */
        }
    });

I have no idea why this is giving me this error. It doesn't work even if I add the "object":{} around the content of the post. I tried changing the UNIX time stamp, I tried changing the message, I tried setting "published": false and no luck.

Any guidance would be amazing.

Simon
  • 3,667
  • 1
  • 35
  • 49
ChainFuse
  • 797
  • 2
  • 10
  • 26

2 Answers2

8

The docs at https://developers.facebook.com/docs/graph-api/common-scenarios#scheduledposts are saying that scheduled_publish_time

should be a UNIX timestamp that is the between 10 minutes and 6 months from the time of publish

As you're only adding 120 seconds, I guess this could be the reason why it doesn't work. Try adding at least 600 seconds and test it again.

https://developers.facebook.com/docs/graph-api/reference/page/feed/#pubfields says this as well.

As @Sahil mentioned, you also need to use a Page Access Token, which needs to be set manually as he described.

Tobi
  • 31,405
  • 8
  • 58
  • 90
8

"published": false should be set in order to publish the scheduled posts. If you carefully see the error after you set this parameter, it says:

(#200) Unpublished posts must be posted to a page as the page itself.

The scheduled posts can be published only using the page access token - logical enough since those who have the permission to manage the pages can schedule the post.

Also, with your code (where you are using a normal user access token), the post is published as yourself not on behalf of the page. And these posts are visible on the side bar not on the main wall- that's not what you are looking for right? :)

So, use the page access token. To get the page access token, get the new user token first with manage_pages permission and make the call-

\GET /{page-id}?fields=access_token

Use this token and make the call to schedule the post-

FB.api(
"/{page-id}/feed",
"POST",
{
    "message": "This is a test message",
    "scheduled_publish_time": Math.round(new Date().getTime() / 1000) + 120,
    "published": false,
    "access_token": "{page-access-token}"
},
function (response) {
    console.log(response);
    if (response && !response.error) {
        /* handle the result */
    }
});

I'm not sure about what exactly your application does, but if getting a never-expiring page access token helps you you can see my answer here for the same.

Hope that helps!

Edit:

As @Tobi has mentioned, also make sure UNIX timestamp is between 10 minutes and 6 months from the time of publish. Since you are using 2 minutes, that may also create problem.

Community
  • 1
  • 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • When the photos are part of a scheduled post, the published, scheduled_publish_time, and unpublished_content_type parameters must be included. – Vansuita Jr. Dec 03 '17 at 23:21
  • @VansuitaJr. Yes, but for photos, you will be using the different endpoint - [`/photos`](https://developers.facebook.com/docs/graph-api/reference/photo). – Sahil Mittal Dec 04 '17 at 07:33