【问题标题】:OAuth2 token with google play services on AndroidOAuth2 令牌与 Android 上的 google play 服务
【发布时间】:2012-11-19 06:25:05
【问题描述】:

我正在尝试使用 Google Play 服务为 Android 上的 Google Cloud Storage 获取 Oauth2 令牌。我正在使用以下代码

try {
        gsToken=GoogleAuthUtil.getToken(this, email,
            "https://www.googleapis.com/auth/devstorage.read_only");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (UserRecoverableAuthException userAuthEx) {
            startActivityForResult(userAuthEx.getIntent(),1);;
    } catch (GoogleAuthException e) {

    }

这会引发 GoogleAuthException。 Google PLAY 服务目前不支持此范围吗??

【问题讨论】:

    标签: android oauth-2.0 google-cloud-storage google-play-services


    【解决方案1】:

    在向 GoogleAuthUtil 询问 OAuth2 令牌时,您需要在范围前加上字符串“oauth2:”。如果您想要多个范围,可以使用空格分隔符列出它们。

    因此,在您的情况下,范围字符串将是“oauth2:https://www.googleapis.com/auth/devstorage.read_only”。

    更多详情请见http://android-developers.blogspot.com/2012/09/google-play-services-and-oauth-identity.html

    【讨论】:

    • 嘿@jham,这曾经对我有用,但就在几天前它停止工作,现在它抛出这个错误 com.google.android.gms.auth.GoogleAuthException: Unknown。知道为什么吗?我的瞄准镜有问题吗? gist.github.com/lawloretienne/7351151
    • 嘿,我遇到了完全相同的问题,GoogleAuthUtil.getToken 以前工作正常,最近它开始给出未知异常。你找到解决办法了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多