I try to implement the code of GmailAPI, but the code doesn't find the credentials.jar. I put a file.exists() verification inside of the google default code, and I find them on that location. So why I see the File Not Found error in the executation ?
Here is the google default code with my file verification:
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
//Verify if the directory of credentials exists:
File credentials = new File(CREDENTIALS_FILE_PATH);
if(credentials.exists()){
System.out.print("The credentials directory exists! --> "+credentials.getAbsolutePath());
}
// Load client secrets.
InputStream in = GmailAPI.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
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(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");
}
And here is the output of execution:
The credentials directory exists! --> C:\rfp\GymSoft\Google\credentials.json
Exception in thread "main" java.io.FileNotFoundException: Resource not found: Google/credentials.json
at apoio.GmailAPI.getCredentials(GmailAPI.java:43)
at apoio.GmailAPI.main(GmailAPI.java:61)
C:\rfp\GymSoft\nbproject\build-impl.xml:1340: The following error occurred while executing this line:
C:\rfp\GymSoft\nbproject\build-impl.xml:981: Java returned: 1
BUILD FAILED (total time: 1 second)