protected GoogleAuthorizationCodeFlow getAuthorizationCodeFlow(boolean usePersistedCredentials)
throws IOException {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
Collection<String> scopes = Arrays.asList(OAUTH2_SCOPE);
GoogleClientSecrets clientSecrets = getClientSecrets();
GoogleAuthorizationCodeFlow flow;
if (usePersistedCredentials) {
flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets, scopes).setAccessType("offline")
.setApprovalPrompt("force").setCredentialStore(getCredentialStore(jsonFactory)).build();