public static void main(final String[] args) throws Exception { final SSLSocketFactory sf = new SSLSocketFactory( SSLContext.getInstance("TLS"), (HostNameResolver) SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final Scheme sch = new Scheme("https", sf, 443); final HttpClient httpClient = new DefaultHttpClient(); httpClient.getConnectionManager().getSchemeRegistry().register(sch); final VerificationCodeReceiver receiver = new PromptReceiver(); final List<String> scopes = Lists.newArrayList("https://www.google.com/m8/feeds"); final JsonFactory jsonFactory = new JacksonFactory(); final HttpTransport transport = new ApacheHttpTransport(httpClient); final Credential credential = OAuth2Native.authorize(transport, jsonFactory, receiver, scopes); System.out.println(credential.getExpiresInSeconds()); System.out.println(credential.getAccessToken()); }
public static void main(String[] args) { // args[0] = command (insert or get) // args[1] = file(s) to interact with // args[2] = received email from galaxy // args[3] = format of the file // args[4] = name of workflow // args[5] = location (local or remote) // args[6] = location of credential file String command = args[0]; String[] filePairs = args[1].split("\\,"); String raw_email = args[2]; String format = args[3]; String workflow = args[4]; String location = args[5]; String credPath = args[6]; String email = null; if (raw_email.contains("__at__")) { String[] email_parts = raw_email.split("\\__at__"); email = email_parts[0] + "@" + email_parts[1]; } else { email = raw_email; } if (format.equals("-")) { format = null; } // authorization java.io.File cred = new java.io.File(credPath); Credential credential = null; try { credential = OAuth2Native.authorize( HTTP_TRANSPORT, JSON_FACTORY, new LocalServerReceiver(), SCOPES, cred); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // set up global Oauth2 instance oauth2 = new Oauth2.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) .setApplicationName("Google-OAuth2Sample/1.0") .build(); // run commands service = new Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build(); perm.setValue(email); String parentFolder = determineParent(email, workflow); for (String fileID : filePairs) { String[] fileName = fileID.split("\\:"); String path = new String(fileName[0]); String[] s = fileName[0].split("/"); String file = s[s.length - 1]; String id = null; if (!file.equals("None")) { id = uploadDriveFile( fileName[1], "No description", parentFolder, "text/plain", file, path, email); } // System.out.println(id); } }