Facebook Graph API:处理超时和错误
我有一个程序会进行大量 fql 和 graph 调用,但我不确定如何处理出现“get”错误或“post”错误时。我如何让它重试?我对这个东西还是新手,但是我可以使用某种 try catch 块吗?如果是这样,我该如何构建它?
我想这可以扩展到 javascript 中的任何获取超时。
谢谢
I have a program that makes a lot of fql and graph calls and I'm not sure how to handle when there's a 'get' error or a 'post' error. How do I get it to retry? I'm still new to this stuff but could I use some sort of try catch block? if so, how do I structure it?
I guess this could be extended to any get timeout in javascript.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询 Facebook Graph API 可能真的很痛苦。首先,我尝试分批切分我的查询。例如,如果我想要我所有朋友的帖子,我首先获取所有朋友的数组,然后为每个 10 个朋友的帖子创建查询,并将它们发送到 Facebook。我对每个响应所做的就是测试响应中是否存在错误,如果是,我重新启动生成批次并发送它们的函数。我使用一个计数器来跟踪发出的查询量。如果我发出 10 个查询,但只收到 9 个,我会在 30 秒后再次重新启动该函数。我使用另一个计数器,重试 3 次后,我向用户显示错误......
Querying Facebook Graph API can be a real pain. First of all, I try to chop my queries in batches. For instance, if I want all of my friends' posts, I first get an array of all my friends, then create queries for their posts for 10 friends each and send them off to facebook. What I do is with every reponse is test if there's an error in the response and if so I restart the function that generates the batches and sends them. I use one counter that keeps track of the amount of queries send out. If I send out 10 queries and I'm getting only 9, I restart the function after 30 seconds again. I use another counter that after 3 retries I show an error to the user...