Google登录获取auth code

Configure an iOS app project as described in Start Integrating.
Find your server client ID on the Credentials page of the Google API Console. Your server client ID is a Web application
type client named something like Web client (Auto-created for Google Sign-in).
Define your app delegate’s application:didFinishLaunchingWithOptions: method as described above in Enable Sign-In, but for this implementation you will set the serverClientID property as shown below.

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

  [GIDSignIn sharedInstance].clientID = @"APP_CLIENT_ID";
  [GIDSignIn sharedInstance].serverClientID = @"SERVER_CLIENT_ID";

  // Additional scopes, if any
  // [GIDSignIn sharedInstance].scopes = @[ @"other_scope" ];

  return YES;
}

After the user is signed in, retrieve the one-time authorization code:

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
    withError:(NSError *)error {
  // Perform any operations on signed in user here.
  // user.serverAuthCode now has a server authorization code!
}

对应链接地址:https://developers.google.cn/identity/sign-in/ios/offline-access
注意事项:
获取auth code需要设置serverClientID,serverClientID为Web client (Auto-created for Google Sign-in)对应的ClientID,
设置完成以后,通过回调方法 - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user里面的user的serverAuthCode字段获取;如果不设置serverClientID,获取的serverAuthCode将会是空值

你可能感兴趣的:(Google登录获取auth code)