I’m working on a Java project that connects to Google Drive API and I need to get the access token and refresh token. When I run my code, I keep getting this error:
public class DriveAuthenticator {
private static final String CLIENT_SECRET_FILE = "credentials.json";
public void authenticateUser() throws IOException {
InputStream inputStream = DriveAuthenticator.class.getResourceAsStream(CLIENT_SECRET_FILE);
// Error occurs when trying to process the JSON
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, inputStream);
}
}
I think I’m missing some dependency or using the wrong version of a library. Which specific JAR file do I need to include in my project to fix this JsonFactory method issue? I’ve tried adding different Google API client libraries but nothing seems to work.
Had this exact issue when migrating an old Google Drive integration. It’s a version mismatch between your Google API client libraries. Fixed it by updating to google-api-client-java 1.32.1 or later and matching it with the same version of google-oauth-client-java. The JsonFactory method signature changed in newer versions, so mixing old/new libraries throws the NoSuchMethodError. Check your Maven or Gradle deps - all Google client libraries need the same version number. Also double-check your credentials.json formatting since auth issues sometimes look like dependency problems.
same issue here last week! you’re probably on an old google-http-client-jackson2 version. update to 1.43.0 or newer - worked for me. also double-check you’ve got jackson-core in your dependencies, that one’s easy to miss.
NoSuchMethodError often occurs when there are version mismatches among your Google API client libraries. I’ve encountered this issue before, and synchronizing the versions helped me resolve it. Ensure that the google-api-client, google-oauth-client, and google-http-client libraries are all aligned in their version numbers. Additionally, look for any outdated transitive dependencies that might be included unintentionally. Utilizing a dependency tree tool can aid in identifying and resolving these conflicts.