min*_*end 4 single-sign-on facebook-ios-sdk ios6
在我的应用程序获得访问在iOS 6的设置中注册的Facebook帐户后,我从我的facebook的隐私设置中撤消了该应用程序.然后我尝试通过调用[FBSession openActiveSessionWithReadPermissions ...]重新连接我的应用程序,并且该方法使用旧的访问令牌创建facebook会话,该令牌已经是INVALID,而不再请求权限授予.
我认为这个问题与这个问题有关(Facebook SDK 3.1 - 验证访问令牌的错误),据说它在SDK 3.1.1中得到修复.
但是,我正在使用SDK 3.1.1并通过在发生无效访问令牌错误时手动调用accountStore renewCredentialsForAccount事件来解决此问题.
基于此线程,我发现验证有效会话的唯一方法是执行简单的图形API调用.如果出现错误,FBSession.activeSession.isOpen将返回NO,这是令牌已过期的良好指示.
+ (void) ValidateSession
{
FBRequest *userDetails = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"/me"];
[userDetails startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *result, NSError *error) {
if (error) {
if (FBSession.activeSession.isOpen) {
// Less probable, so check error code.
} else {
// Bingo: here we know for sure that the token was useless.
// Expected behavior: reauthorize.
}
} else if (result) {
NSLog(@"%@", result);
// token is valid, continue
}
}];
}
Run Code Online (Sandbox Code Playgroud)
即使在删除应用程序后,iOS似乎仍保留Facebook令牌,因此在需要时再次确保令牌有效是一种很好的做法.
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |