Example usage for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets set

List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets set

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets set.

Prototype

@Override
    public GoogleClientSecrets set(String fieldName, Object value) 

Source Link

Usage

From source file:cn.edu.fudan.se.helpseeking.test.GetRefreshToken.java

License:Open Source License

public static void main(String[] args) throws Exception {
    // Get the client ID and secret from the ads.properties file.
    // If you do not have a client ID or secret, please create one in the
    // API console: https://code.google.com/apis/console#access and set it
    // in the ads.properties file.

    //   [cseFduTest]
    //         cx=014132305786414512501:prmarh9sn8k
    //         projectid=rosy-resolver-863
    //         key=AIzaSyAlqmv7SHFrJptyWdEKjXnR5_PkTVAHpfs
    //         csename=Helpseekingfdu
    //         OAuth=AIzaSyAlqmv7SHFrJptyWdEKjXnR5_PkTVAHpfs
    //         clientid=433540504100-ogf00jmc1kj142ctognbn8cbjbjegegt.apps.googleusercontent.com
    //         CLIENTSECRET=dBJKZCKSyRwnFK73dsGxDcRX

    GoogleClientSecrets clientSecrets = null;
    try {//from   w  w  w .  j av a  2 s .c  o m
        clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.DFP).fromFile().build();
        clientSecrets.set("client_id",
                "33540504100-ogf00jmc1kj142ctognbn8cbjbjegegt.apps.googleusercontent.com");
        clientSecrets.set("client_secret", "dBJKZCKSyRwnFK73dsGxDcRX");

    } catch (ValidationException e) {
        System.err.println(
                "Please input your client ID and secret into your ads.properties file, which is either "
                        + "located in your home directory in your src/main/resources directory, or "
                        + "on your classpath. If you do not have a client ID or secret, please create one in "
                        + "the API console: https://code.google.com/apis/console#access");
        System.exit(1);
    }

    // Get the OAuth2 credential.
    Credential credential = getOAuth2Credential(clientSecrets);

    System.out.printf("Your refresh token is: %s\n", credential.getRefreshToken());

    // Enter the refresh token into your ads.properties file.
    System.out.printf("In your ads.properties file, modify:\n\napi.dfp.refreshToken=%s\n",
            credential.getRefreshToken());
}