使用 Graph API,我通过 POST 到/me/feed 连接来发布故事。我从 Facebook 返回成功或错误结果。到目前为止,一切都很好。偶尔会出现API耗时过长导致连接超时的情况。在那种情况下,我不确定请求是成功还是失败(即请求可能从未到达 Facebook,或者它可能成功但结果从未返回给我)。你如何处理这种情况?
更多详情: 我在 Facebook 和 Twitter 上发布了很多帖子,所以超时的情况经常发生。使用 Twitter,解决方案很简单。如果请求第一次超时,我就再试一次。 Twitter 检测到重复项,因此如果帖子第一次成功发布,那么我将在第二次请求时收到“重复状态”错误,我知道我不需要再重试。
但 Facebook 不会检测重复项,因此如果我重试发布请求,我将冒着将帖子的两个副本发布到用户墙上的风险,这并不好。另一方面,如果我不重试,我就有帖子根本无法发布的风险。想法?
最佳答案
I get back a success or an error result from Facebook.
嗯。当我发布到 Graph API 时,我收到错误或帖子的 ID。我从来没有看到任何成功消息。您围绕 API 使用什么 SDK?
Once in a while, the API takes a long time and the connection times out.
通常当事情运行缓慢时,这是由于未指定 channelUrl
。参见 https://developers.facebook.com/docs/reference/javascript/
It is important for the channel file to be cached for as long as possible. When serving this file, you must send valid Expires headers with a long expiration period. This will ensure the channel file is cached by the browser which is important for a smooth user experience. Without proper caching, cross domain communication will become very slow and users will suffer a severely degraded experience.
关于facebook - 发布到 Facebook 时如何避免重复发布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8817124/