撤銷存取權杖並取消連結應用程式

強烈建議您提供透過 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:

接著,您可以在回呼區塊中回應成功中斷連線 並在應用程式或後端程式碼中觸發任何適當的邏輯。