Hi Google APIs Team,
I have this error :
java.lang.NoSuchMethodError: com.google.api.client.http.HttpRequest.setResponseReturnRawInputStream(Z)Lcom/google/api/client/http/HttpRequest;
For the line :
ValueRange response = service.spreadsheets().values().get(spreadsheetId, range).execute();
My Code is :
package technicalFunctions
class ReadSpreadsheet {
private static final String CREDENTIALS_FILE_PATH = "C:/Users/soukna/nefertiti_auto/client_secret.json";
private static final String APPLICATION_NAME = "gcp-nerfertiti";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
private static final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS_READONLY);
//cette méthode valide d'abord notre demande et crée une connexion entre la bibliothèque d'API Google Sheets.
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
// Load client secrets.
InputStream in1 = new FileInputStream(CREDENTIALS_FILE_PATH);
if (in1 == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in1));
// Build flow and trigger user authorization request.
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");
}
/**
* Permet de lire La G-Sheet
*/
@Keyword
public static List<List<Object>> getSpreadSheetRecords(String range) throws IOException, GeneralSecurityException {
final NetHttpTransport HTTP_TRANSPORT = new com.google.api.client.http.javanet.NetHttpTransport()
final String spreadsheetId = "1LXrgBIZx5K0XXWXBGaJGId1i3r8q_P6dGKhVacCVclo";
System.out.println("iCi");
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY,getCredentials(HTTP_TRANSPORT)).setApplicationName(APPLICATION_NAME).build();
ValueRange response = service.spreadsheets().values().get(spreadsheetId, range).execute();
System.out.println("LA"+range+" "+spreadsheetId);
List<List<Object>> values = response.getValues();
if (values == null || values.isEmpty()) {
System.out.println("No data found.");
return null;
} else {
System.out.println("found");
return values;
}
}
}
3 Weeks and no answer about this issue.
Please HELP ME !!!