2023-01-03 15:47:53.655 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2023-01-03 15:47:53.679 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Draft/LireGoogleSheet2
2023-01-03 15:47:56.138 INFO c.k.k.c.keyword.builtin.CommentKeyword - beforeTestCase: Test Cases/Draft/LireGoogleSheet2
Test Cases/Draft/LireGoogleSheet2
[:]
2023-01-03 15:48:00.595 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ❌ Could not find matching constructor for: com.google.auth.http.HttpCredentialsAdapter(com.google.api.client.http.javanet.NetHttpTransport)
2023-01-03 15:48:00.601 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/Draft/LireGoogleSheet2 FAILED.
Reason:
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.google.auth.http.HttpCredentialsAdapter(com.google.api.client.http.javanet.NetHttpTransport)
at technicalFunctions.SheetsQuickstart.main(Google.groovy:77)
at technicalFunctions.SheetsQuickstart.invokeMethod(Google.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:55)
at LireGoogleSheet2.run(LireGoogleSheet2:1)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1672757257875.run(TempTestCase1672757257875.groovy:25)
2023-01-03 15:48:00.629 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/Draft/LireGoogleSheet2
package technicalFunctions
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.auth.http.HttpCredentialsAdapter
import com.google.auth.oauth2.ServiceAccountCredentials
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;
public class SheetsQuickstart {
private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
//"{\"token\": \"ya29.a0AX9GBdVKGcNktf7Kp3SRbmPNPkbP50PHmfdwcwVv_a5KmKHi1T5MnSkYAYxPGa4Sp06pjyoYK-JSjiEXgPTrpCnox_XxgmR5rBR2F-AqpmSHMbhd0Vvjx0Gk0-vnYwl_ZdUkmI9S2FnVCZ-n-t8-njh7CXDqaCgYKAUESARASFQHUCsbC-IjwNq233hJJB7Cr0fcEtw0163\", \"refresh_token\": \"1//03u8-Hc-Sqi2fCgYIARAAGAMSNwF-L9IroaG-Lst4-ZWEDb-d3Wd92pwKo93ONo_1LT_BzPd9hH1-9qgCiQfNuk4gfZ3Zl9HbqyA\", \"token_uri\": \"
https://oauth2.googleapis.com/token\", \"client_id\": \"
565804531014-b33pl9umdp1taftei18imhdhd7lhpq13.apps.googleusercontent.com\", \"client_secret\": \"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\", \"scopes\": [\"
https://www.googleapis.com/auth/drive\", \"
https://www.googleapis.com/auth/spreadsheets\"], \"expiry\": \"2022-12-22T11:21:28.724497Z\"}";
/**
* Global instance of the scopes required by this quickstart.
* If modifying these scopes, delete your previously saved tokens/ folder.
*/
private static final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS_READONLY);
private static final String CREDENTIALS_FILE_PATH = "C:/Users/soukna/nefertiti_auto/client_secret.json";
/**
* Creates an authorized Credential object.
*
* @param HTTP_TRANSPORT The network HTTP Transport.
* @return An authorized Credential object.
* @throws IOException If the credentials.json file cannot be found.
*/
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT)
throws IOException {
// Load client secrets.
InputStream intr = new FileInputStream(CREDENTIALS_FILE_PATH);
if (intr == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(intr));
// 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");
/*ServiceAccountCredentials credentials = (ServiceAccountCredentials) GoogleCredentials.getApplicationDefault();
credentials.createScoped(SCOPES);
return new HttpCredentialsAdapter(credentials);*/
}
/**
* Prints the names and majors of students in a sample spreadsheet:
*
https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit */
public static void main(String args) throws IOException, GeneralSecurityException {
// Build a new authorized API client service.
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
final String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
final String range = "Class Data!A2:E";
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpCredentialsAdapter(HTTP_TRANSPORT)).setApplicationName(APPLICATION_NAME).build();
ValueRange response = service.spreadsheets().values().get(spreadsheetId, range).execute();
List<List<Object>> values = response.getValues();
if (values == null || values.isEmpty()) {
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(4));
}
}
}
}