简体   繁体   English

Facebook iOS SDK 3.1.1:如何检查过期的令牌?

[英]Facebook iOS SDK 3.1.1: How to check for expired token?

How do I check if the access token is expired via the iOS SDK? 如何通过iOS SDK检查访问令牌是否已过期?

I call [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:NO completionHandler:nil] when my app starts to load the session from the cache. 当我的应用开始从缓存中加载会话时,我调用[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:NO completionHandler:nil]

Active session then looks like this: 活动会话如下所示:

<FBSession: 0x1fdcbae0,
state: FBSessionStateOpen,
loginHandler: 0x0,
appID: 1234567890,
urlSchemeSuffix: ,
tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x1fdcb840>, 
expirationDate: 4001-01-01 00:00:00 +0000,
refreshDate: 2012-12-10 07:09:18 +0000,
attemptedRefreshDate: 0001-12-30 00:00:00 +0000,
permissions:(
    email
)

FBSession.activeSession.isOpen always returns YES. FBSession.activeSession.isOpen始终返回YES。 Why is expirationDate in the distant future? 为什么expirationDate在遥远的将来?

On my server I call a method via PHP, and I'm told the session has expired. 在我的服务器上,我通过PHP调用了一个方法,并被告知会话已过期。 How should I handle this? 我该如何处理?

The best way to check for an expired token is to actually try an API call and handle errors. 检查令牌是否过期的最好方法是实际尝试API调用并处理错误。 For example, after your open call you can call startForMeWithCompletionHandler: in the completion handler. 例如,在打开调用之后,您可以在完成处理程序中调用startForMeWithCompletionHandler:。 In the startForMeWithCompletionHandler: completion handler you can check error. 在startForMeWithCompletionHandler:完成处理程序中,您可以检查错误。

See this doc for more info on how you can handle the errors you may get back: https://developers.facebook.com/docs/reference/api/errors/ 有关如何处理可能会返回的错误的更多信息,请参阅此文档: https : //developers.facebook.com/docs/reference/api/errors/

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

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