Facebook Graph 错误消息的可靠性
有没有可靠的方法从 Facebook 平台获取访问令牌错误?
我们的 iOS/Android 应用程序需要保存用户的 Facebook 会话。这很好,只是我们从 Facebook 收到的身份验证错误似乎不一致。
本质上,如果我们从 Facebook 收到错误,我们想知道这是否需要用户重新进行身份验证,或者是否是由于间歇性错误(即由于某种原因受到速率限制)。
大多数 Facebook 图表错误似乎在错误消息文本正文中包含错误代码。
有些则不然。
例如
{"error":{"message":"验证访问令牌时出错:会话无效,因为用户注销。","type":"OAuthException"}}
不包含错误代码,因此检查的唯一方法针对此错误的方法是对“message”进行字符串比较。这似乎是一种非常不可靠的检查错误的方法。
似乎几乎可以检查 json 字符串中的“type”变量是否指示“OAuthException”,除了如果用户受到速率限制,那么也会抛出 OAuthException,但不需要用户重新登录后,只需要他们等待一小会儿,就可以停止发帖了。
我已经看到这里列出的操作方法: https://developers.facebook.com/blog/post /500 但这仍然存在一个问题,即如果用户碰巧过于热衷于在自己的墙上发帖,我的游戏将要求用户重新登录 Facebook。
那么,有没有可靠的方法从 facebook 平台获取错误呢?
现在我能找到的最佳解决方案是解析消息字符串中的错误代码,如果没有找到任何错误代码,则重新解析字符串以查找特定消息(例如“验证访问令牌时出错”),最后如果可以的话无法确定错误是什么,只是恐慌并注销用户。
Is there a reliable way of getting access token errors from the facebook platform?
Our iOS/Android App needs to save the users Facebook session. This is fine except that authentication errors we get from Facebook seem to be inconsistent.
Essentially, if we get an error from facebook, we want to know if this requires the user to reauthenticate or if it's due to an intermittent error (i.e. they are being rate limited for some reason).
Most facebook graph errors seem to include an error code in the body of the error message text.
Some do not.
e.g
{"error":{"message":"Error validating access token: The session is invalid because the user logged out.","type":"OAuthException"}}
Does not contain an error code, so the only way to check against this error is to do a string comparison on "message". That seems a remarkably unreliable way of checking for errors.
It seems ~almost~ possible to check to see if the "type" variable in the json string indicates an "OAuthException", except that if the user is rate limited, then that will throw an OAuthException as well but it doesn't require the user to log back in, it only requires them to wait a little while and stop posting so much.
I have seen the How-To listed here: https://developers.facebook.com/blog/post/500 but that will still have the problem that my games will require users to log back into facebook if they happen to be over-enthusiastic about posting to their wall.
So, is there a reliable way of getting errors from the facebook platform?
Right now the best solution I can find is to parse the message string for error codes, and if I don't find any then reparse the string looking for specific messages (such as "Error validating access token") and then finally if I can't determine what the error is, just panic and log the user out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是我还没有找到处理这个问题的好方法。到目前为止,我发现的最佳解决方案是查看错误是否是 OAuthException,将错误消息与不需要重新身份验证的“可接受的失败”白名单进行比较,但如果错误与上的任何错误都不匹配有了这个白名单,我假设用户必须通过 Facebook 重新进行身份验证。
作为参考,我发现的唯一可以列入白名单的错误是“用户速率受限”错误。为了检测到这一点,我检查错误消息是否包含子字符串“(#341)”,这是该错误的错误代码(并不是说该错误是错误消息中包含错误代码的少数错误之一身体)。
Unfortunately I haven't found a great way of handling this. The best solution I've found so far is to look to see if the error is an OAuthException, compare the error message against a white list of "acceptable failures" that do not require reauthentication, but if the error does not match any error on this white list, I assume that the user has to reauthenticate with Facebook.
For reference, the only error I've found that can be whitelisted is the "user is rate limited" error. To detect this, I check to see if the error message contains the substring "(#341)", which is the error code of this error (not that this error is one of the few errors that contains an error code in the error message body).