Reputation: 424
I'm developing a web application using the Enterprise Edition of Java where I need the Google Drive API. And at some point, I need to get clients "authorization" to access their Drive and for that (according to what I understood), I need to obtain Google API credentials (the oAuth ones) but this is a long process and as I'm doing this a school project, I can't wait. So I need a way to test the API without having to go through the heavy process of obtaining the credentials needed for published apps.
I am testing the Drive API on this project https://github.com/google/google-api-java-client-samples/tree/master/drive-cmdline-sample
the problem is in this function
private static Credential authorize() throws Exception {
// load client secrets
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(testApi.class.getResourceAsStream("/client_secrets.json")));
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive "
+ "into drive-cmdline-sample/src/main/resources/client_secrets.json");
System.exit(1);
}
I need to somehow obtain client_secrets.json
but I can't without credentials or at least, that's what I understood from the researches and reading I did.
This function is imported from com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
if that helps.
Thank you !
Upvotes: 0
Views: 615
Reputation: 106
Yes you are right, you need to authenticate in order to use Google Drive API. Otherwise, the service can not tell who is accessing/requesting data and if this person has access to it.
Don’t worry, you don’t have to wait, however you do have to perform certain steps in order to get this credential. I understand that you want to grant access by other clients to get their information with this API.
In order to do this, you first need a GCP project with the Drive API enabled. https://developers.google.com/drive/api/v3/quickstart/java
By clicking on “Enable the Drive API” will automatically create a project, most likely called quickstart with the Drive API already enabled.
Then you have to set up a service account to access to this project. https://developers.google.com/identity/protocols/OAuth2ServiceAccount
Once this is done, the file that will be downloaded are the credentials that you need in order to authenticate. (“client_secret.json”)
Upvotes: 1