Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created March 21, 2022 18:01
Show Gist options
  • Save GaetanoPiazzolla/ab5c540bb8d60642e171d969807b9391 to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/ab5c540bb8d60642e171d969807b9391 to your computer and use it in GitHub Desktop.
Boilerplate code to start working with the Form and the Drive APIs from Google
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.forms.v1.Forms;
import java.io.IOException;
import java.security.GeneralSecurityException;
public class Boilerplate {
private static final String APPLICATION_NAME = "google-form-api-project";
private static Drive driveService;
private static Forms formsService;
static {
try {
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
driveService = new Drive.Builder(GoogleNetHttpTransport.newTrustedTransport(),
jsonFactory, null)
.setApplicationName(APPLICATION_NAME).build();
formsService = new Forms.Builder(GoogleNetHttpTransport.newTrustedTransport(),
jsonFactory, null)
.setApplicationName(APPLICATION_NAME).build();
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment