Hi,
I am trying solve a problem that I have with my web services.
I have had reading all document about outh2.0 in Java and to integrate
Spreadsheet and I have 3 problems.
My web application that I use contains files jsp and Servlet.
I have a form where the user fill fields and then clic the button for
submit.
Then it start flow token.
If first the page call to put email, then if the user Accept or denege
access, but them...I do not know controle anything.
1.- The page "callback", how many methods I need? what kind the page need:
JSP or html o Servlet? I dont know.
I know that in my api console, I configure (client id, client secret, i can
download file json, Authorized JavaScript origins, Authorized redirect URIs )
but i do not know in my code where to see it.
I have in Java this:
public class SheetsQuickstart {
/** Application name. */
private static final String APPLICATION_NAME = "Name_APP";
/** Directory to store user credentials for this application. */
private static final java.io.File DATA_STORE_DIR = new java.io.File(
System.getProperty("user.home"),
"credentials/sheets.googleapis.com-java-quickstart");
/** Global instance of the {@link FileDataStoreFactory}. */
private static FileDataStoreFactory DATA_STORE_FACTORY;
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY =
JacksonFactory.getDefaultInstance();
/** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT;
/** Global instance of the scopes required by this quickstart.
*
* If modifying these scopes, delete your previously saved credentials
* at ~/.credentials/sheets.googleapis.com-java-quickstart
*/
private static final List<String> SCOPES =
Arrays.asList(SheetsScopes.SPREADSHEETS_READONLY);
static {
try {
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
/**
* Creates an authorized Credential object.
* @return an authorized Credential object.
* @throws IOException
*/
public static Credential authorize() throws IOException {
/** Load client secrets.
* */
InputStream in = new FileInputStream("\client_secret.json");
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT,
JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
LocalServerReceiver localReceiver = new
LocalServerReceiver.Builder().setPort(8080).build();
Credential credential = new AuthorizationCodeInstalledApp(flow,
localReceiver).authorize("user");
System.out.println("Credentials saved to " +
DATA_STORE_DIR.getAbsolutePath());
return credential;
}
/**
* Build and return an authorized Sheets API client service.
* @return an authorized Sheets API client service
* @throws IOException
*/
public static Sheets getSheetsService() throws IOException {
Credential credential = authorize();
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
}
public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Sheets service = getSheetsService();
// Prints the names and majors of students in a sample spreadsheet:
String spreadsheetId = "Id spreadsheet";
String range = "A4:C6";
ValueRange response = service.spreadsheets().values()
.get(spreadsheetId, range)
.execute();
List<List<Object>> values = response.getValues();
if (values == null || values.size() == 0) {
System.out.println("No data found.");
} else {
System.out.println("Name, Major");
for (List<?> row : values) {
// Print columns A and E, which correspond to indices 0 and 4.
System.out.printf("%s, %s\n", row.get(0), row.get(1),
row.get(2));
}
}
}
}
I have my file json and it is OK.
I do not see where I need to see access_toke or how I can get it.
Someone have any example with this or can help me please?
Thanks!!!!
--
You received this message because you are subscribed to the Google Groups
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.