So, I have learned pretty much all of my java knowledge from fiddling around with things. That being said I have a working application with everything except for the saving and loading done.
I want to save and load from a google spreadsheet.
I looked up the Google API documentation for it, and have installed the API on my project... I've also pretty much copied some example I saw. (What is an example of using OAuth 2.0 and Google Spreadsheet API with Java?)
I want to know what the next step is. Right now I have it redirecting to google because I don't know where else to redirect it to (its a desktop app, not a web app), and I don't understand how to use the code appended to the google.com url.
Yes I'm aware this looks like I'm just copying and pasting, but really this is the only hurdle for the program working so I'd appreciate some help :/
Thanks!
package com.thepanthurr.security;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.*;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
public class InputOutput {
public static final String USERNAME = "Redacted.apps.googleusercontent.com";
public static final String PASSWORD = "Redacted";
public static final String SHEETURL = "https://www.google.com/";
private static final List<String> SCOPES = Arrays.asList("https://www.googleapis.com/auth/spreadsheets");
public static void read() throws IOException, URISyntaxException {
Credential credential = getCredentials();
System.out.println(credential.toString());
}
public static Credential getCredentials() throws IOException, URISyntaxException {
HttpTransport transport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String authorizationUrl =
new GoogleAuthorizationCodeRequestUrl(USERNAME, SHEETURL, SCOPES).build();
Desktop.getDesktop().browse(new URL(authorizationUrl).toURI());
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String code = in.readLine(); //NO CLUE WHAT TO PUT HERE
GoogleTokenResponse response =
new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, USERNAME, PASSWORD,
code, SHEETURL).execute();
return new GoogleCredential.Builder().setClientSecrets(USERNAME, PASSWORD)
.setJsonFactory(jsonFactory).setTransport(transport).build()
.setAccessToken(response.getAccessToken()).setRefreshToken(response.getRefreshToken());
//What do I do after I receive the credentials?
}
}