アクセス トークンを取り消してアプリの接続を解除する

Google でログインしたユーザーが Google アカウントをアプリから切断できるようにすることを強く推奨します。ユーザーがアカウントを削除した場合、アプリが Google API から取得した情報を削除する必要があります。

次のコード例は、アプリがユーザーに代わって付与されたアクセス トークンをプログラムで取り消し、ユーザーのアカウントをアプリから切断する方法を示しています。

Swift

GIDSignIn.sharedInstance.disconnect { error in
    guard error == nil else { return }

    // Google Account disconnected from your app.
    // Perform clean-up actions, such as deleting data associated with the
    //   disconnected account.
}

Objective-C

[GIDSignIn.sharedInstance disconnectWithCompletion:^(NSError * _Nullable error) {
    if (error) { return; }

    // Google Account disconnected from your app.
    // Perform clean-up actions, such as deleting data associated with the
    //   disconnected account.
}];

disconnectWithCompletion: メソッドは、ユーザーのログアウトに加えて、アカウントの接続解除とトークンの取り消しを行います。disconnectWithCompletion: を呼び出す前にユーザーをログアウトしてはなりません。

コールバック ブロック内で接続解除の成功に応答し、アプリまたはバックエンド コードで適切なロジックをトリガーできます。