gpt4 book ai didi

javascript - Facebook 错误 : (#100) The specified scheduled publish time is invalid

转载 作者:行者123 更新时间:2023-11-30 19:33:44 37 4
gpt4 key购买 nike

我正在构建一个平台来创建和组织社交媒体帖子,并通过 Facebook Graph API 将它们发布到 Facebook。我已经设置了获取所需访问 token 的逻辑,并立即将帖子发布到 Facebook 页面,效果非常好。但是,如果我尝试安排帖子,我总是会收到错误

(#100) 指定的预定发布时间无效”。

我使用 POST 请求到 https://graph.facebook.com/page_id/feed 以使用以下参数查询 Facebook Graph API

access_token=...
message=Test
published=false
scheduled_publish_time=time

我在哪里计算 UNIX 时间戳

const minutes = 15;
const time = new Date().getTime() + minutes * 60 * 1000;

考虑到我在功能中安排了 15 分钟的帖子,我假设我已经考虑了所有必要的要求 (https://developers.facebook.com/docs/graph-api/using-graph-api/common-scenarios#scheduledposts)。

编辑

正如@04FS 所指出的,您需要以秒而不是毫秒为单位给出时间戳。因此以下解决了我的问题

const minutes = 15;
const time = Math.round((new Date().getTime() + minutes * 60 * 1000) / 1000);

最佳答案

const minutes = 15;
const time = new Date().getTime() + minutes * 60 * 1000;

JavaScript 的 Date 对象以毫秒为单位工作,而不是秒。您的 JS 代码当前给出的值约为 1558015867708,这将是 07/23/51341 @ 1:28am (UTC) 的 unix 时间戳

API 需要以秒为单位的正确 unix 时间戳,而不是毫秒。

关于javascript - Facebook 错误 : (#100) The specified scheduled publish time is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56170141/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com