Я пытаюсь обновить ячейку в таблице Google Таблиц. Я уверен, что идентификатор листа, учетные данные, страница в таблице («Имена») и ячейка («B2») верны. Stacktrace:
private static final String APPLICATION_NAME = "....."; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static final List SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS); private static final String CREDENTIALS_FILE_PATH = "......."; private static final String TOKENS_DIRECTORY_PATH = "tokens";
private Sheets sheetsService;
public GoogleSheets() throws Exception { final com.google.api.client.http.HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); this.sheetsService = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); }
private Credential getCredentials(final com.google.api.client.http.HttpTransport HTTP_TRANSPORT) throws Exception { InputStream in = new FileInputStream(CREDENTIALS_FILE_PATH); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH))) .setAccessType("offline") .build(); LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build(); return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); }
public void updateCellValue(String spreadsheetId, String range, String value) { try { ValueRange body = new ValueRange().setValues( Collections.singletonList(Collections.singletonList(value)) ); sheetsService.spreadsheets().values() .update(spreadsheetId, range, body) .setValueInputOption("RAW") .execute(); System.out.println("Cell updated: " + range + " with value: " + value); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { try { GoogleSheets service = new GoogleSheets(); service.updateCellValue("1OF8UZnI8AZ0ExmTxXdq7NmXCQo_8dg4pTV6Z8e4KQKQ", "Names!B2", "123"); } catch (Exception e) { e.printStackTrace(); } } } [/code] Почему я получаю здесь ответ 404?