问题
I've gone through all of the steps listed here: https://developers.google.com/drive/v2/web/quickstart/java and now when I run my project, it gives me a 400 error, redirect url mismatch on Chrome.
I've tried following multiple instructions from here: Google OAuth 2 authorization - Error: redirect_uri_mismatch but I am having two key problems: When I go to register the URI in my developers console, I have no field to put the redirect URI's in, and my redirect URI is different every time, from what I can tell.
How can I add a redirect URI, and also whenever I run the program, the redirect URI seems to be different every time.
Taken from the console ( run 1, and run 2):
redirect_uri=http://localhost:62210/
redirect_uri=http://localhost:62349/
So I have no idea how to account for dynamic redirect URI's.
My code matches the quickstart/java link exactly
Here is the console output:
Feb 08, 2016 7:42:38 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: C:\Users\Speedy Octopus\.credentials\drive-java-quickstart
Feb 08, 2016 7:42:38 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\Speedy Octopus\.credentials\drive-java-quickstart
2016-02-08 19:42:38.378:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2016-02-08 19:42:38.378:INFO::jetty-6.1.26
2016-02-08 19:42:38.388:INFO::Started SocketConnector@localhost:62210
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=20967686237-compute@developer.gserviceaccount.com&redirect_uri=http://localhost:62210/Callback&response_type=code&scope=https://www.googleapis.com/auth/analytics.readonly
Attempting to open that address in the default browser now...
回答1:
I ran into the exact same problem the other day, basically google is not very clear about the fact that they need both the address that they will be returning to and the callback uri. In your development console where you have registered your project, under 'credentials', 'Authorized redirect URIs' you need to add your callback uri, in this case http://localhost:62210/Callback
. Without that google cannot be sure it is returning to the right uri.
来源:https://stackoverflow.com/questions/35282133/google-drive-rest-api-drivequickstart-error-400-redirect-uri-mismatch-java