撤销授予我的应用 Google Drive API 的访问权限

2024-02-15

如何撤销已授予我的 Google 云端硬盘网络应用程序的访问权限,以便在用户下次使用时重新请求权限?


要撤销您的访问令牌,您需要“GET”(!)此网址:https://accounts.google.com/o/oauth2/revoke?token= https://accounts.google.com/o/oauth2/revoke?token={令牌} 其中 {token} 是您的令牌的值,如下所述:https://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke https://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke

对于 Java API(不知道是否适用于其他语言),截至 2012 年 9 月 9 日,还没有相应的 API。 我设法用以下代码撤销令牌:

class myGoogleApi {
    private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

    ...

    public revoke(String token) {
        HttpRequestFactory factory = HTTP_TRANSPORT.createRequestFactory();
        GoogleUrl url = new GoogleUrl("https://accounts.google.com/o/oauth2/revoke?token="+token);
        HttpRequest request = factory.buildGetRequest(url);
        HttpResponse response = request.execute();
        ...
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

撤销授予我的应用 Google Drive API 的访问权限 的相关文章

随机推荐