简体   繁体   English

我的Facebook活动的事件时间显示不正确(通过Javascript提交)

[英]Event Time displaying incorrectly for my Facebook event (submitted via Javascript)

I am currently writing a site that interacts with Facebook and creates events for users. 我目前正在撰写一个与Facebook交互并为用户创建活动的网站。 I am using Javascript to submit the event, which is submitting successfully. 我正在使用Javascript提交事件,该事件已成功提交。 The problem is, the time that is displayed on Facebook is way off from the time I am submitting. 问题是,Facebook上显示的时间与我提交的时间相差甚远。

Here is my code: 这是我的代码:

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...
});

Yes, we're using some Django in there. 是的,我们在那里使用了一些Django。

{{ show_time.start_time|date:'U' }} will put in an epoch timestamp. {{show_time.start_time | date:'U'}}将放入一个纪元时间戳。 I have also send in an ISO 8601 datetime with the same results. 我还发送了一个ISO 8601日期时间,结果相同。 Currently, we have no timezone information in the datetimes. 目前,我们在日期时间内没有时区信息。 I am not sure if that is causing the problem though, because to test, I had appended -06:00 to the start_time, and it still showed up wrong on Facebook. 我不确定这是否会导致问题,因为要测试,我已经将-06:00添加到start_time,并且它仍然在Facebook上显示错误。

What is confusing me is in the docs on Facebook, they show a curl line that supposedly creates an event, and the start_time they send in is an epoch timestamp. 令我困惑的是,在Facebook的文档中,它们显示了一条据说会创建一个事件的卷曲线,并且它们发送的start_time是一个纪元时间戳。 In other parts of the same page, they say the start_time must be ISO 8601. I have also read that you need to convert your datetime to Pacific time, then convert to an epoch timestamp, then submit that as the start_time. 在同一页面的其他部分,他们说start_time必须是ISO 8601.我还读过你需要将你的日期时间转换为太平洋时间,然后转换为纪元时间戳,然后将其作为start_time提交。 I just want to know what the correct way is. 我只是想知道正确的方法是什么。 The Facebook docs seem to be pretty bad at this, so I'm hoping SO can help! Facebook的文档在这方面看起来很糟糕,所以我希望SO能提供帮助! Who has actually created an event with Facebook through the Javascript API and had it show up with the correct time on the site? 谁通过Javascript API实际上通过Facebook创建了一个活动,并让它显示在网站上的正确时间? How did you do it? 你是怎么做到的?

First of all, there is a bug on Facebook event timezone management. 首先,Facebook事件时区管理存在一个错误。 If you check an Event on the API and on Facebook, you can see different dates. 如果您在API和Facebook上查看活动,您可以看到不同的日期。 The right date on the API and the wrong date on Facebook, because you add the event by the API. API上的正确日期和Facebook上的错误日期,因为您通过API添加事件。 If you created the Event on Facebook, the API will show the wrong date. 如果您在Facebook上创建了活动,则API将显示错误的日期。

If you try any API event call you can see the format used: 如果您尝试任何API事件调用,您可以看到使用的格式:

"end_time": "2010-03-15T00:30:00+0000"

As you can notice, the date/time format is ISO 8601 and you should use this but, probably, epoch timestamp should work. 您可以注意到,日期/时间格式是ISO 8601,您应该使用它,但可能,时间戳应该有效。 By looking at the timezone (UTC, +0000) you can guest that you should convert your local date to UTC (+0000) but this is the problem. 通过查看时区(UTC,+ 0000),您可以将guest将您的本地日期转换为UTC(+0000),但这是问题所在。

The date must be converted to PST/PDT timezone, but keeping the UTC timezone designator (+0000) as Mike Lambert found http://bugs.developers.facebook.net/show_bug.cgi?id=12558 日期必须转换为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. 我想在这一点上API是错误的,但可以预见错误,修复它只会破坏其他开发人员。 So you could argue it's a documentation bug: http://developers.facebook.com/docs/reference/api/event 所以你可以说这是一个文档错误: 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. 应该确实说这些ISO格式的UTC时间都应转换为PST / PDT以检索用户输入的事件时间。 (Which is not the UTC/GMT time the event will actually occur.) (这不是事件实际发生的UTC / GMT时间。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM