令牌无效 - 令牌无效:双腿OAuth的用户无效

时间:2012-03-26 09:52:04

标签: java oauth gdata

我正在尝试使用OAuth2.0访问Google文档。我从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

2 个答案:

答案 0 :(得分:1)

xoauth_requestor_id参数仅适用于用于对Google Apps用户进行身份验证的双腿Oauth(2LO)。我不认为可以使用2LO对常规Gmail用户进行身份验证。

你有没有在这里看到3脚Oauth的例子http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples

答案 1 :(得分:1)

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

相关问题