我目前正在编写一个与 Facebook 交互并为用户创建事件的网站。我正在使用 Javascript 提交事件,提交成功。问题是,Facebook 上显示的时间与我提交的时间相差甚远。
这是我的代码:
var event = {
start_time: '{{ show_time.start_time|date:'U' }}',
name: 'Movie Night: ' + '{{ show_time.movie.title }}'
};
FB.api('/me/events', 'post', event, function(response) {
// Send invites, etc...
});
是的,我们在那里使用了一些 Django。
{{ show_time.start_time|date:'U' }} 将放入纪元时间戳。我还发送了具有相同结果的 ISO 8601 日期时间。目前,我们在日期时间中没有时区信息。我不确定这是否是问题的原因,因为为了测试,我将 -06:00 附加到 start_time,但它在 Facebook 上仍然显示错误。
让我感到困惑的是 Facebook 上的文档,它们显示了一条 curl 线,据称会创建一个事件,并且它们发送的 start_time 是一个纪元时间戳。在同一页的其他部分,他们说开始时间必须是 ISO 8601。我还读到您需要将日期时间转换为太平洋时间,然后转换为纪元时间戳,然后将其作为开始时间提交。我只想知道什么是正确的方法。 Facebook 文档在这方面似乎很糟糕,所以我希望 SO 可以提供帮助!谁实际上通过 Javascript API 在 Facebook 上创建了一个事件,并让它以正确的时间显示在网站上?你是怎么做到的?
最佳答案
首先,Facebook 事件时区管理存在一个错误。如果您在 API 和 Facebook 上查看事件,您会看到不同的日期。 API 上的正确日期和 Facebook 上的错误日期,因为您通过 API 添加事件。如果您在 Facebook 上创建了事件,API 将显示错误的日期。
如果您尝试任何 API 事件调用,您可以看到使用的格式:
"end_time": "2010-03-15T00:30:00+0000"
正如您所注意到的,日期/时间格式是 ISO 8601,您应该使用它,但也许纪元时间戳应该可以工作。通过查看时区(UTC,+0000),您可以猜测您应该将本地日期转换为 UTC(+0000),但这就是问题所在。
日期必须转换为 PST/PDT 时区,但保留 UTC 时区指示符 (+0000) 正如 Mike Lambert 发现的 http://bugs.developers.facebook.net/show_bug.cgi?id=12558
I guess at this point the API is wrong, but predictably wrong, and fixing it would just break other developers. So you could argue it's a documentation bug: http://developers.facebook.com/docs/reference/api/event
It should really say these ISO-formatted UTC times should all be converted to PST/PDT to retrieve the time of the event as entered by the user. (Which is not the UTC/GMT time the event will actually occur.)
关于javascript - 我的 Facebook 事件的事件时间显示不正确(通过 Javascript 提交),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3944729/