撤消访问令牌并断开应用

强烈建议您为使用 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: 之前让用户退出登录。

然后,您可以在回调块中响应成功断开关联的操作,并在您的应用或后端代码中触发任何适当的逻辑。