Google 和 Facebook 在同一个应用程序中登录

Google and Fb sign-in in same app

我正在尝试在应用程序中集成 fb 和新 google 登录,但遇到某些问题,有人可以帮忙吗。

其实我在AppDelegate.m写过这个

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSError* configureError;
    [[GGLContext sharedInstance] configureWithError: &configureError];
    NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

    [GIDSignIn sharedInstance].delegate = self;

    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                    didFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {


    return [[FBSDKApplicationDelegate sharedInstance] application:application                                                         openURL:url                                              sourceApplication:sourceApplication                                                       annotation:annotation] && [[GIDSignIn sharedInstance] handleURL:url
                                     sourceApplication:sourceApplication
                                            annotation:annotation];
}

然后我在另一个 class

中创建 google 登录按钮
- (void)viewDidLoad {
    [super viewDidLoad];

    fbLogingButton = [[FBSDKLoginButton alloc]init];
    fbLogingButton.delegate = self;
    fbLogingButton.center = self.view.center;
    [self.view addSubview:fbLogingButton];
    fbLogingButton.readPermissions =
    @[@"public_profile", @"email", @"user_friends"];

    googleSignInButton = [[GIDSignInButton alloc]initWithFrame:CGRectMake(120, 370,50, 150)];
    [self.view addSubview:googleSignInButton];


    [GIDSignIn sharedInstance].uiDelegate = self;

    // Do any additional setup after loading the view, typically from a nib.
}

但应用程序在

中启动时崩溃
[[GGLContext sharedInstance] configureWithError: &configureError];

如果我评论说点击登录按钮它会崩溃

崩溃日志显示

2015-09-07 17:10:38.272 DemoAppSep[62471:3858047] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|' First throw call stack: ( 0 CoreFoundation 0x00000001042fbc65 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000103f92bb7 objc_exception_throw + 45 2 CoreFoundation
0x00000001042fbb9d +[NSException raise:format:] + 205 3 DemoAppSep 0x00000001017581ef -[GIDSignIn assertValidParameters] + 77 4
DemoAppSep 0x000000010175a589 -[GIDSignIn signInWithOptions:] + 52 5 DemoAppSep
0x000000010175e5c6 -[GIDSignInButton pressed] + 331 6 UIKit
0x00000001046f6da2 -[UIApplication sendAction:to:from:forEvent:] +

将此用于 FaceBook https://developers.facebook.com/docs/ios/getting-started

将此用于 GooglePlus https://developers.google.com/+/mobile/ios/getting-started

必须遵循所有步骤

最后在 AppDelegate.m

- (BOOL) application:(UIApplication *) application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
BOOL wasHandled=false;;
if ([url.scheme hasPrefix:@"fb"]) {

      wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
    //Facebook callback
}
else       //Google Plus callback
{
  wasHandled=  [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];

}

NSLog ( @"application openURL");
NSLog ( @"URL = %@", url);
NSLog ( @"Application = %@", sourceApplication);

return wasHandled;
}

会work.Thankyou