ChatGPT解决这个技术问题 Extra ChatGPT

Google OAUTH: The redirect URI in the request did not match a registered redirect URI

I am trying to make an upload to YouTube from my Java based web app, I spent a few days to understand what and where is the problem and I cannot get it, for now I am pulling my hair out off my head.

I registered my web app in Google Console, so I got a pair of Client ID and Secret and a possibility to download JSON type file with my config.

So here is the config:

{
    "web":{
        "auth_uri":"https://accounts.google.com/o/oauth2/auth",
        "client_secret":"***",
        "token_uri":"https://accounts.google.com/o/oauth2/token",
        "client_email":"***",
        "redirect_uris":["http://localhost:8080/WEBAPP/youtube-callback.html","http://www.WEBAPP.md/youtube-callback.html"],
        "client_x509_cert_url":"***",
        "client_id":"***",
        "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
        "javascript_origins":["http://www.WEBAPP.md/"]
    }
}

How is possible that I am getting the default URL from Google?

The redirect URI in the request: http://localhost:8080/Callback did not match a registered redirect URI

It always gives me the default http://localhost:8080/Callback URL instead of mine.

And IDE console shows me that:

Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?client_id=***&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload Attempting to open that address in the default browser now...

I am using the last version of dependencies: google-api-services-youtube v3-rev99-1.17.0-rc and google-api-services-youtubeAnalytics v1-rev35-1.17.0-rc


s
smholloway

I think I encountered the same problem as you. I addressed this problem with the following steps:

1) Go to Google Developers Console

2) Set JavaScript origins:

http://localhost

3) Set Redirect URIs:

http://localhost:8080

http://localhost:8080/Callback


Hi @Multitut Did this workout for you? I am getting the following error the redirect uri in the request does not match the ones authorized for the oauth
Hey @Max, I have followed your steps in the google developer console. It worked. Thank you so much mate.
S
Shashanth

When your browser redirects the user to Google's oAuth page, are you passing as a parameter the redirect URI you want Google's server to return to with the token response? Setting a redirect URI in the console is not a way of telling Google where to go when a login attempt comes in, but rather it's a way of telling Google what the allowed redirect URIs are (so if someone else writes a web app with your client ID but a different redirect URI it will be disallowed); your web app should, when someone clicks the "login" button, send the browser to:

https://accounts.google.com/o/oauth2/auth?client_id=XXXXX&redirect_uri=http://localhost:8080/WEBAPP/youtube-callback.html&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload

(the callback URI passed as a parameter must be url-encoded, btw).

When Google's server gets authorization from the user, then, it'll redirect the browser to whatever you sent in as the redirect_uri. It'll include in that request the token as a parameter, so your callback page can then validate the token, get an access token, and move on to the other parts of your app.

If you visit:

http://code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow

You can see better samples of the java client there, demonstrating that you have to override the getRedirectUri method to specify your callback path so the default isn't used.

The redirect URIs are in the client_secrets.json file for multiple reasons ... one big one is so that the oAuth flow can verify that the redirect your app specifies matches what your app allows.

If you visit https://developers.google.com/api-client-library/java/apis/youtube/v3 You can generate a sample application for yourself that's based directly off your app in the console, in which (again) the getRedirectUri method is overwritten to use your specific callbacks.


From how it works it seems that the library won't let me to pass my customized URL, instead it will pass the standard one, or I made something wrong, or I missed a detail. I thought it would get the URIs from client_secret.json. Then for what is the config file?
Edited my answer above to provide more details for your comment.
Thanks Jarom, that was the problem, I did not override the method, now it works. Thanks a lot to you, you saved my time.
@jlmcdonald I am facing similar problem, can you help me stackoverflow.com/questions/34316162/…
Well explained jlmcdonald. Kudos.
d
datalifenyc

I was able to get mine working using the following Client Credentials:

Authorized JavaScript origins

http://localhost

Authorized redirect URIs

http://localhost:8090/oauth2callback

Note: I used port 8090 instead of 8080, but that doesn't matter as long as your python script uses the same port as your client_secret.json file.

Reference: Python Quickstart


excellent, this helped. I saw the address of the redirect URI that was not allowed in the error message and had to use that instead (obv :)) but it all worked out.
I
Ikai Lan

You need to go into the developer console and set

http://localhost:8080/WEBAPP/youtube-callback.html

as your callback URL.

This video is slightly outdated, as it shows the older Developer Console instead of the new one, however, the concepts should still apply. You need to find your project in the developer console and register a callback URL.


Please read my post carefully, I already register it, and downloaded my config, config is in the first post, and here is the screenshot of my web app config from Google Console img89.imageshack.us/img89/5770/4p7q.png , so all seams to be right, but it isn't working at all, I tried to delete and recreate the config about 10 times even with old Google Console. I thought it is the problem with localhost, so I tried even on production how you can see from screenshot, and this isn't working too.
You need to set the redirect URI in the web console, not just in your JSON config file.
I provided a screenshot above :), do you saw it? there is a screenshot from the Google Console setup.
B
Ben D

I thought I had this configured but it turns out I set the URL in the wrong place. I followed the URL provided in the Google error page and added my URL here. Stupid mistake from my part, but easily done. Hope this helps


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now