【问题标题】:Gmail API error: redirect_uri_mismatch when trying to authenticate. (PHP)Gmail API 错误:尝试进行身份验证时出现 redirect_uri_mismatch。 (PHP)
【发布时间】:2018-05-16 20:58:37
【问题描述】:

我正在使用 PHP 来做我的 gmail API。所以这就是我的客户的设置方式。

$client = new Google_Client();
$client->setClientId('42XXXXXX3p0o9XXXXXXXXXXXXXXXXX.apps.googleusercontent.com');
$client->setClientSecret('XXXXXXrLXX22Ld-1XXXXXXX');
$client->setRedirectUri('https://mywebsite.com/AilaGmail/gmail.php'); 
$client->addScope('https://mail.google.com/');

当我第一次点击登录并授权我的 API 时,我收到了这个错误:

**Error: redirect_uri_mismatch
Request Details
response_type=code
access_type=online
client_id=XXXXX-pXXXXXXX3.apps.googleusercontent.com
redirect_uri=https://mywebsite.com/AilaGmail/gmail.php
state=
scope=https://mail.google.com/
approval_prompt=auto**

我已经尝试了一些解决方案,例如将 redirect_uri 更改为 'postmessage',但后来又遇到了另一个错误:

Error: invalid_request
origin parameter is required!

我能做什么?我正在使用 php!请帮忙...

编辑 1* 我尝试了更多解决方案,例如更改 client_secret.json 文件,但也没有用:/

【问题讨论】:

  • 这可能与您在 Google 配置面板中指定的 redirect_uri 与您在 HTTP 调用中指定的不同有关
  • 另外,您可以访问此SO post 以进一步讨论您遇到该错误的原因。
  • 但是我没有找到谷歌的配置。当您选择“网络应用程序”时,它在那里,但是当您使用 PHP 时没有“重定向 uri”字段(在这种情况下为选项“其他”)

标签: php redirect uri gmail-api mismatch


【解决方案1】:

好的,伙计们,我做到了。我的代码缺少一个重要参数:

$client->setAuthConfig('client_secret.json');

我仍然无法使用我得到的代码,但不匹配错误已解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-22
    • 2015-01-24
    • 1970-01-01
    • 2017-10-23
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多