Alexander Widak - 2014-02-26

For quick starting see example class de.deltatree.oauth2.limited.TestAuthenticationFlow:

package de.deltatree.oauth2.limited;

import java.io.IOException;

import com.google.api.client.repackaged.com.google.common.base.Strings;

public class TestAuthenticationFlow {

    public static void main(String[] args) throws IOException,
            InterruptedException {
        String clientId = "XXXXXXXXXXXXXXXXXXXXXX";
        String secret = "YYYYYYYYYYYYYYYYYYYYYY";
        String scope = "https://www.google.com/m8/feeds/";

        LimitedDeviceHelper ldh = new LimitedDeviceHelper(clientId, secret,
                scope);

        UserToken userToken = ldh.requestUserToken();
        System.out.println(Strings.repeat("*", 33));
        System.out.println("Please authenticate the app :");
        System.out.println(Strings.repeat("*", 33));
        System.out.println(userToken);
        System.out.println(Strings.repeat("*", 33));

        AccessToken accessToken = ldh.doAuthorizationLoop(userToken,
                new AuthorizationLoopInfoHandler() {

                    private long counter = 0;

                    public boolean goOn(UserToken userToken,
                            AccessToken accessToken) {
                        System.out.println("waiting (" + ++counter + ") : "
                                + accessToken);
                        return true; // waiting forever ...
                    }
                });
        System.out.println(Strings.repeat("*", 33));
        System.out.println("You have successfully authenticated the app :");
        System.out.println(Strings.repeat("*", 33));
        System.out.println(accessToken);

        AccessToken newAccessToken = ldh.refreshAccessToken(accessToken);
        System.out.println(Strings.repeat("*", 33));
        System.out.println("AccessToken has been refreshed successfully :");
        System.out.println(Strings.repeat("*", 33));
        System.out.println(newAccessToken);

    }

}
 

Last edit: Alexander Widak 2014-02-27