【问题标题】:Token invalid - Invalid token: Invalid user for the two legged OAuth令牌无效 - 令牌无效:两条腿 OAuth 的用户无效
【发布时间】:2012-04-09 19:56:17
【问题描述】:

我正在尝试使用 OAuth2.0 访问谷歌文档。我从 Google API 控制台获得了客户端 ID 和密钥。但是当我运行这段代码时,我得到了异常。如果我遗漏了任何东西,你可以给我建议吗..

String CONSUMER_KEY = ".....apps.googleusercontent.com";
        String CONSUMER_SECRET = "sM52Mts_d7snVIomnJaQkjkA";

        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
        oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);

        DocsService client = new DocsService("testing");
        client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());

        // Retrieve user's list of Google Docs
        String user = "xesunny@gmail.com";
        URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full" +
                              "?xoauth_requestor_id=" + user);

        DocumentListFeed resultFeed = client.getFeed(feedUrl, DocumentListFeed.class);
        for (DocumentListEntry entry : resultFeed.getEntries()) {
          System.out.println(entry.getTitle().getPlainText());
        }

例外:

com.google.gdata.util.AuthenticationException: Token invalid - Invalid token: Invalid user for the two legged OAuth

令牌无效 - 令牌无效:两条腿 OAuth 的用户无效

令牌无效 - 令牌无效:两条腿 OAuth 的用户无效

错误 401

【问题讨论】:

    标签: java oauth gdata


    【解决方案1】:

    xoauth_requestor_id 参数仅适用于用于对 Google Apps 用户进行身份验证的 2-legged Oauth (2LO)。我认为不可能使用 2LO 对普通 gmail 用户进行身份验证。

    您在http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples 看到过 3-legged Oauth 的示例

    【讨论】:

      【解决方案2】:

      您使用的客户 ID 似乎不是服务帐号。仅服务帐户支持双腿身份验证。如果您创建一个新的服务帐户并使用其客户端 ID 和密钥(一个 RSA 私钥),您的代码应该可以工作。

      【讨论】:

        猜你喜欢
        • 2011-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-09
        相关资源
        最近更新 更多