我正在尝试将我的应用程序转换到新的Facebook SDK 3.1(支持iOS6身份验证).
我工作得很好,所以我决定从FB网站上的授权应用程序列表中删除该应用程序,以测试iOS是否会再次请求许可.
现在我第一次调用会[FBRequest requestForMe]导致此错误:
响应:
{
"error": {
"message": "Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons.",
"type":"OAuthException",
"code":190,
"error_subcode":460
}
}
Run Code Online (Sandbox Code Playgroud)
一些细节:
我正在尝试按如下方式打开会话:
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[self presentPostOptions];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation]; …Run Code Online (Sandbox Code Playgroud) 我正在使用Facebook SDK 3.1.1在我的iOS应用程序中实现FB Connect.这在新的FB集成(在iOS上登录)或通过Web视图回退到正常授权(在两种情况下都没有安装本机Facebook应用程序)的简单情况下工作正常.我在iOS级别切换帐户时会出现此问题.注销并使用其他FB用户帐户登录.
要登录/授权我执行:
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
Run Code Online (Sandbox Code Playgroud)
如果然后每次获得FBSessionStateClosedLoginFailed,即使我执行了closeAndClearTokenInformation达到该状态的时间:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
NSLog(@"Session State Changed: %u", [[FBSession activeSession] state]);
switch (state) {
case FBSessionStateOpen:
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
NSLog(@"FBSessionStateClosedLoginFailed ERROR: %@", [error description]);
[[FBSession activeSession] closeAndClearTokenInformation];
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
但是,每次重试都会收到相同的状态.我的日志说明如下:
FBSDKLog: FBSession **INVALID** transition from FBSessionStateCreated to FBSessionStateClosed
FBSDKLog: FBSession transition from FBSessionStateCreated to FBSessionStateCreatedOpening
FBSDKLog: FBSession transition from …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中加入一些Facebook集成.在这一点上,我已经设法登录,发布到朋友的墙上,检索朋友列表等等.除了一件事,一切都还好......
如果用户从您的Facebook设置/应用程序中删除应用程序 ,然后进入iOS应用程序,则代码无法识别Facebook应用程序已从用户设置中删除并假设已登录(这是问题,因为如果用户试图发布到朋友的墙上,应用程序什么都不做).
然后,用户关闭iOS应用程序并重新启动它...通过此重新启动,iOS应用程序"已修复"并检测到用户不再登录.
在用户从设置中删除Facebook应用程序之后,我无法立即检测到该时刻,以便将登录流程带给用户...
这是我的代码:
在我的应用程序的第一个场景......
if([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
{
NSLog(@"Logged in to Facebook");
[self openFacebookSession];
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"You're already logged in to Facebook" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertDialog show];
[alertDialog release];
return YES;
}
else{
NSLog(@"Not logged in to Facebook"); //Show the login flow
return NO;
}
Run Code Online (Sandbox Code Playgroud)
这是openFacebookSession的代码
-(void)openFacebookSession
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { …Run Code Online (Sandbox Code Playgroud) 我正在使用3.1 Facebook SDK与iOS 6 Facebook设置在设置和我的应用程序授权.
这完美地执行:
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *fbSession, FBSessionState fbState, NSError *error) { ... }
Run Code Online (Sandbox Code Playgroud)
但是现在当我试图获取"我"信息时,我收到了一个错误:
com.facebook.sdk:ParsedJSONResponseKey = {
body = {
error = {
code = 190;
"error_subcode" = 463;
message = "Error validating access token: Session has expired at unix time 1348704000. The current unix time is 1348706984.";
type = OAuthException;
};
};
code = 400;
}
Run Code Online (Sandbox Code Playgroud)
如果我看[error code]它等于5.我登录后不应该有一个有效的访问令牌吗?我需要拨打重新授权吗?
更新:重新授权没有帮助.奇怪的是,我的activeSession的accessToken总是回归相同.尽管调用了closeAndClearToken.
如何从facebook ios sdk 3.1获取访问令牌?
我已经获得了facebook的登录信息.登录完成后,应用程序就会出现在前台.虽然我还不知道如何从中获取访问令牌.
我从[[FBSession activeSession] accessToken]得到null; 命令.
有任何想法吗?