简体   繁体   English

Facebook SDK + iPhone SDK + SSO

[英]Facebook SDK + iPhone SDK + SSO

I know that this question has been asked, but I have been reading through threads all day and have applied all of the fixes I could find and am still having an issue. 我知道有人问过这个问题,但是我整天都在阅读线程,并应用了我能找到的所有修复程序,但仍然有问题。

I am trying to implement Facebook SDK's new SSO feature to allow my app to authenticate with Facebook's app instead of a webView. 我正在尝试实现Facebook SDK的新SSO功能,以允许我的应用通过Facebook的应用而非WebView进行身份验证。 When my app switches to Facebook's app, it says loading for a few seconds and switches back but the token is still null. 当我的应用程序切换到Facebook的应用程序时,它说加载几秒钟并切换回去,但令牌仍然为空。 I have a feeling it has to do with the URL scheme for my app but I have followed many tutorials and am fairly confident that my current plist values are correct: 我觉得这与我的应用程序的URL方案有关,但是我已经阅读了许多教程,并且对我当前的plist值正确是很有信心的: 在此处输入图片说明

Here is the code I have implemented in my appDelegate and viewController files: appDelegate.h 这是我在appDelegate和viewController文件中实现的代码:appDelegate.h

Facebook *facebook;

appDelegate.m appDelegate.m

// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [facebook handleOpenURL:url]; 
}

// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [facebook handleOpenURL:url]; 
}

SecondViewController.m SecondViewController.m

-(IBAction) fbButton {
    //FACEBOOK INTEGRATION
    appDelegate.facebook = [[Facebook alloc] initWithAppId:@"222087841143437" andDelegate:appDelegate];

    // Check and retrieve authorization information
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        appDelegate.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        appDelegate.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![appDelegate.facebook isSessionValid]) {
        appDelegate.facebook.sessionDelegate = self;
        [appDelegate.facebook authorize:permissions];
        NSLog(@"Token: %@", [defaults objectForKey:@"FBAccessTokenKey"]);
    } else {
        NSLog(@"Already logged in!");

    }
    [appDelegate.facebook requestWithGraphPath:@"me" andDelegate:self];

}


- (void)request:(FBRequest *)request didLoad:(id)result {
    NSString *nameID = [[NSString alloc] initWithFormat:@"%@ (%@)", [result objectForKey:@"name"], [result objectForKey:@"id"]];
    NSMutableArray *userData = [[NSMutableArray alloc] initWithObjects:
                                [NSDictionary dictionaryWithObjectsAndKeys:
                                 [result objectForKey:@"id"], @"id", 
                                 nameID, @"name", 
                                 [result objectForKey:@"picture"], @"details", 
                                 nil], nil];

    [userData release];
    [nameID release];
    NSLog(@"DATA RECEIVED: %@", result);
}

- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"request:didReceiveResponse:");
}

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);
};
- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[[appDelegate facebook] accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[[appDelegate facebook] expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    NSLog(@"Facebook Logged in!");

    [appDelegate.facebook requestWithGraphPath:@"me" andDelegate:self];


}

I know that I call [appDelegate.facebook requestWithGraphPath:@"me" andDelegate:self] twice, but I don't think that's the problem. 我知道我曾两次致电[appDelegate.facebook requestWithGraphPath:@“ me” andDelegate:self],但我不认为这是问题所在。

Here is a snippet from the console when I press the login button: 当我按下登录按钮时,这是控制台中的一个片段:

2011-10-18 15:37:33.287 Track[2235:707] Token: (null)
2011-10-18 15:37:36.578 Track[2235:707] request:didReceiveResponse:
2011-10-18 15:37:36.584 Track[2235:707] The operation couldn’t be completed. (facebookErrDomain error 10000.)
2011-10-18 15:37:36.586 Track[2235:707] Err details: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x1ce480 {error=<CFBasicHash 0x1c9560 [0x3e368630]>{type = mutable dict, count = 2,
entries =>
    2 : <CFString 0x19a830 [0x3e368630]>{contents = "type"} = <CFString 0x11d230 [0x3e368630]>{contents = "OAuthException"}
    3 : <CFString 0x1f5b60 [0x3e368630]>{contents = "message"} = <CFString 0x1f8a70 [0x3e368630]>{contents = "An active access token must be used to query information about the current user."}

I appreciate the help and I really hope I didn't miss a discussion on here that solves this problem. 感谢您的帮助,我真的希望我不要错过这里讨论解决此问题的讨论。 Here are a few (of the many) that I have read through and had no success in finding a solution 以下是我(其中很多)已阅读但仍未成功找到解决方案的信息

How to implement Single Sign On (SSO) using facebook ios sdk for iphone Facebook SSO and request iOS SDK Facebook API for iPhone Error: An active access token must be used 如何使用用于iPhone iPhone的facebook ios sdk实现单点登录(SSO) 以及如何 为iPhone 请求iOS SDK Facebook API错误:必须使用活动访问令牌

确保您的Facebook应用程序(您在Facebook上创建的实际应用程序)不在沙盒模式下,并且确保您当前登录的Facebook应用程序(iPhone Facebook客户端)用户是该应用程序的开发者。

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

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