Legacy Support for ClientLogin (Deprecated)

Sample program

The following sample program shows ClientLogin used for authentication. You must manually fill in the username and password in order for this sample to work. Otherwise, you will likely get an HTTP 403 Forbidden status code.

Do not base new work on the sample; it is provided only for ClientLogin legacy support.

import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;

import java.io.IOException;
import java.lang.System;

public class ClientLoginSample {
  public static void main(String[] args) throws IOException {
    // HttpTransport used to send login request.
    HttpTransport transport = new NetHttpTransport();
    try {
      // authenticate with ClientLogin
      ClientLogin authenticator = new ClientLogin();
      authenticator.transport = transport;
      // Google service trying to access, e.g., "cl" for calendar.
      authenticator.authTokenType = "cl";
      authenticator.username = "username";
      authenticator.password = "password";
      System.out.println("Authentication succeeded.");
    } catch (HttpResponseException e) {
      // Likely a "403 Forbidden" error.
      throw e;