php - 带有 Laravel 的 YouTube Data API v3:重定向 URI 不匹配
问题描述
我确实设置了两个 Google 项目,一个用于localhost
生产,另一个用于生产。本地项目 ( http://localhost
) 按预期工作,但服务器 ( https://example.com
) 上的相同代码引发以下错误:
array:2 [▼
"error" => "redirect_uri_mismatch"
"error_description" => "Bad Request"
]
我已经交叉验证了所有 URL 并正确设置它们;即使从控制台更新后,我也下载了新的 JSON 文件并等待了一天。还是同样的问题。
不知道出了什么问题;任何帮助,将不胜感激。
解决方案
您的帖子暗示您正在开发服务器端 Web 应用程序。
在这种情况下,您显示的错误表明您在 Google Developers Console 中为相应项目设置的重定向 URI 与您的应用在调用 API 时实际发送到 API的重定向 URI 不匹配:
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope(GOOGLE_SERVICE_YOUTUBE::YOUTUBE_FORCE_SSL);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
// offline access will give you both an access and refresh token so that
// your app can refresh the access token without user interaction.
$client->setAccessType('offline');
// Using "consent" ensures that your application always receives a refresh token.
// If you are not using offline access, you can omit this.
$client->setApprovalPrompt("consent");
$client->setIncludeGrantedScopes(true); // incremental auth
确保双方(Google Developers Console 中的配置设置和应用程序本身)就要使用的重定向 URI 达成一致。
推荐阅读
- python - 读取视频时的 OpenCV 帧速率与用于捕获的帧速率不同
- typescript - 使用接口时显示打字稿方法返回值
- html - 填充剩余空间的容器内的可滚动元素
- javascript - 如何每天从前一个计数器增加一个特定的数字?
- ios - 如何通过相机视图与其他一些 UIView 一起使用具有相机视图的实时应用程序屏幕
- typescript - 声明仅应用特定类型的对象键的方法的方法是什么?
- loopback4 - 如何在环回 4 中根据用户角色提供部分访问权限?
- python - 如何将一组矩阵转换为熊猫中的数据框?
- android - Android Oreo 下 BOOT COMPLETED 后服务未重启
- kubernetes - 如何通过 microk8s 使用 Anthos Connect