oAuth 2.0 for google apps audit api

I am using following method to get oAuth credentials for google apps audit api

    String CONSUMER_KEY = "CONSUMER_KEY";
    String CONSUMER_SECRET = "CONSUMER_SECRET";

    GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
    oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
    oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
    oauthParameters
                .setScope("https://apps-apis.google.com/a/feeds/compliance/audit/ https://www.googleapis.com/auth/userinfo.email");
    oauthParameters
                .setOAuthCallback("url_where_I_handle_callback_from_google");

    GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(
                new OAuthHmacSha1Signer());
    oauthHelper.getUnauthorizedRequestToken(oauthParameters);
    req.getSession().setAttribute("tokenSecret",
                    oauthParameters.getOAuthTokenSecret());
    String approvalPageUrl = oauthHelper
                    .createUserAuthorizationUrl(oauthParameters);
    resp.sendRedirect(approvalPageUrl);

    //handle on oAuth callback , retrieving the oAuth Token
    String oAuthToken = req.getParameter("oauth_token");
    if (oAuthToken != null) {
        GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(
                new OAuthHmacSha1Signer());
        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
        oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
        oauthParameters.setOAuthTokenSecret((String) req.getSession()
                .getAttribute("tokenSecret"));
        oauthHelper.getOAuthParametersFromCallback(req.getQueryString(),
                oauthParameters);

        String accessToken = oauthHelper.getAccessToken(oauthParameters);
        String accessTokenSecret = oauthParameters.getOAuthTokenSecret();
    }

then to get the signed audit service I am using this :

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

    AuditService service = new AuditService(<domain_name>,<app_id>);
    service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());

Now the problem is that it's oAuth 1 as I am using OAuthHmacSha1Signer() .I want to do oAuth 2.0 but I am not getting any resources which tells how to do it using java clients. The CONSUMER_KEY and CONSUMER_SECRET,I am getting from https://accounts.google.com/ManageDomains while I want to use Client_Id and Client_Secret from https://code.google.com/apis/console for oAuth 2.

Please provide some code example for oAuth 2 using google java client libs or provide some links o tutorials.

Thanks


I hope one of these would help you out -

http://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/oauth/TwoLeggedOAuthExample.java

http://code.google.com/p/google-oauth-java-client/source/browse/dailymotion-cmdline-sample/src/main/java/com/google/api/services/samples/dailymotion/cmdline/DailyMotionSample.java?repo=samples

A lot of snippets that you might find useful, on this link - http://code.google.com/p/google-oauth-java-client/wiki/OAuth2

链接地址: http://www.djcxy.com/p/80054.html

上一篇: 在GAE应用上使用python客户端API更新谷歌电子表格

下一篇: oAuth 2.0适用于谷歌应用程序审计api