错误:invalid_request redirect_uri的参数值无效:Uri必须包含可打印的ASCII字符:

I Created Client Id and API Key in the Google Developer Console, I given same url in google console and in my config file

This is my url:

https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A81%2Fmoviemuseui%2Fpublic%2Flogin%2FcheckLogin+&client_id=XXXXXXXX-xxxxxxxxxxxxxxxxx.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&access_type=offline&approval_prompt=force

I am getting a error

  1. That’s an error.

Error: invalid_request

Invalid parameter value for redirect_uri: Uri must consist of printable ASCII characters: localhost:81/moviemuseui/public/login/checkLogin

How to solve this, I can't find the problem.

2个回答

Excluded US-ASCII Characters disallowed within the URI syntax:

   control     = <US-ASCII coded characters 00-1F and 7F hexadecimal>
   space       = <US-ASCII coded character 20 hexadecimal>
   delims      = "<" | ">" | "#" | "%" | <">

There are also some characters that may be allowed in URI syntax but can cause problems.

"{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"

And the following characters are absolutely reserved for a query component and they are used for specific meaning in the protocol.

";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ","

You don't need to url encode everything. The first call to for authentication just displays a page to your users for them to approve your access. It is a normal HTTP GET you can test it in any webbrowser.

The following works:

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&response_type=code

This one adds your redirect uri, remember redirect uri should point to the page where you would like to handle authentication.

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=http:// localhost:81/moviemuseui/public/login/checkLogin/Filename.php&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&response_type=code

I have a tutorial that explains how the calls should be put together: Google 3 legged oauth2 flow

Question: If you are using the Google-api-php-client why are you building this manually?

Your error Redirect_URI: must match the page where you would like to handle the authentication. For example: http:// localhost/google-api-php-client-samples/oauth2.php It should be set in the developer console, and used in your script.

duan2891
duan2891 你能检查一下这个stackoverflow.com/questions/34316162 / ..
大约 4 年之前 回复
dongmo6937
dongmo6937 重定向uri必须与要返回身份验证的URI匹配。 如果您在自己的网站上托管它,那么它必须是该网址,并且必须在Google Developers控制台中将其设置为相同的网址。
大约 4 年之前 回复
donglun1918
donglun1918 我们可以使用其他网址,如任何网站网址而不是localhost作为redirect_uri吗?
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问