【问题标题】:Error: invalid_request Invalid parameter value for redirect_uri: Uri must consist of printable ASCII characters:错误:invalid_request redirect_uri 的参数值无效:Uri 必须由可打印的 ASCII 字符组成:
【发布时间】:2015-01-25 16:04:54
【问题描述】:

我在 Google Developer Console 中创建了客户端 ID 和 API 密钥,我在 google 控制台和我的配置文件中给出了相同的 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

我遇到了一个错误

  1. 这是一个错误。

错误:invalid_request

redirect_uri 的参数值无效:Uri 必须由 可打印的 ASCII 字符: 本地主机:81/moviemuseui/public/login/checkLogin

如何解决,我找不到问题。

【问题讨论】:

    标签: php codeigniter google-api-php-client


    【解决方案1】:

    只需检查URI 是否不包含任何空格。我也遇到了同样的问题,最后删除空格解决了。

    【讨论】:

    • 这增加了什么其他答案没有?
    【解决方案2】:

    您的重定向 uri 不得包含空格“”

    【讨论】:

    • 天啊复制粘贴,都没注意到
    【解决方案3】:

    您不需要对所有内容进行 url 编码。对身份验证的第一次调用只是向您的用户显示一个页面,供他们批准您的访问。这是一个普通的 HTTP GET,您可以在任何网络浏览器中对其进行测试。

    以下作品:

    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

    这个添加你的重定向 uri,记住重定向 uri 应该指向你想要处理身份验证的页面。

    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

    我有一个解释如何将调用放在一起的教程:Google 3 legged oauth2 flow

    问题:如果您使用的是 Google-api-php-client,为什么要手动构建它?

    您的错误 Redirect_URI: 必须与您要处理身份验证的页面相匹配。例如:http://localhost/google-api-php-client-samples/oauth2.php 它应该在开发人员控制台中设置,并在您的脚本中使用。

    【讨论】:

    • 我们可以在这里使用任何其他 url 像任何 siteurl 而不是 localhost 作为 redirect_uri 吗?
    • 重定向 uri 必须与您希望身份验证返回的 URI 匹配。如果您将其托管在您的网站上,那么它必须是该网址,并且必须在 Google Developers 控制台中设置为相同的网址。
    【解决方案4】:

    URI 语法中不允许使用的排除 US-ASCII 字符:

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

    还有一些字符在 URI 语法中可能是允许的,但可能会导致问题。

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

    并且以下字符是绝对保留给查询组件的,它们用于协议中的特定含义。

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

    【讨论】:

      猜你喜欢
      • 2020-02-18
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多