Reputation: 546
I am new to google drive and started with the tutorial quickstart. After numerous attampts I run the program successfully. However I had permission and authorisation problems when I was trying to delete files.
Drive service = getDriveService();
service.files().delete("FileId").execute();
So I decide to change the URL in the client_secret.json,
From: "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
To: "auth_provider_x509_cert_url":"https://www.googleapis.com/auth/drive"
in the hope that I would now get the permission to delete files. However after executing the program again I didn't get the authorization tab of the internet browser like before.
As an example of the mentioned tab, here an image from google playground:
That's the reason why I delted the connection from my app to google drive website:
In addition i recreated also the client_secret.json file. However when I now execute the program I get only this error, independent what I am doing.
Exception in thread "main" com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Token has been revoked."
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at main.java.DriveQuickstart.main(DriveQuickstart.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
So the two questions are what should i do to get the tutorial running again and how to set the permissions so that i can delete files?
Upvotes: 0
Views: 935
Reputation: 4467
I had a slightly different case. After getting the example in the Quick Start Guide to work a few months ago, I got the following error today when rerunning it.
Exception in thread "main" com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Bad Request"
}
Since the tokens were stored in TOKENS_DIRECTORY_PATH ("tokens")
, the token stored there probably became invalid. Deleting directory tokens
allowed me to once again get the browser page to select a gmail account to proceed with. Everything worked from there.
Upvotes: 0
Reputation: 546
Now I find out the problem: I had to delete the directory "user.home/.credentials/drive-api-quickstart". After that I can give the program the authorisation, which it needs. Hope that someone will help this post ;)
Upvotes: 4