Laravel 如何在 Youtube 上获取访问令牌 API
Laravel How to get access token on Youtube API
我在已经启用路由选项时遇到需要令牌错误,但它仍然无法正常工作。
通过使用这个库:https://github.com/JoeDawson/youtube
你能帮我解决这个问题吗?
代码:
class VideoController extends BaseController {
public function __construct(){
}
public function store(Request $request){
$video = Youtube::upload($request->file("video")->getPathName(), [
'title' => 'My Video',
'description' => 'This video is uploaded through API.',
'tags' => ['api', 'youtube'],
]);
return $this->sendResponse($video);
}
}
根据该包的文档,您需要执行这些步骤,因为您可能遇到 refresh_token 的问题(我猜您没有任何令牌在您的数据库中,必须在登录后创建 google)
重要的是,在您开始上传视频之前,您已经确认您的数据库中有一个 refresh_token,否则这些步骤必须有所帮助。
1- 删除 youtube_access_tokens table 中的所有标记。
2- 在 youtube.php
中启用路由
3- Re-authenticate 与 Google
4- 检查您的 youtube_access_tokens table 并找到最近的 令牌 。
5- 检查令牌并确保 refresh_token 存在。
6- 在 config/youtube.php
中禁用身份验证路由
简而言之,用于创建令牌您需要访问您的 Google console 并添加您的 URL 作为回调(本地主机)。
然后在您的应用程序中,访问 http://localhost:8000/youtube/auth - 您将被重定向到 Google 并被要求登录。这是您获得令牌的时间,然后您可能不会再看到该错误!
我在已经启用路由选项时遇到需要令牌错误,但它仍然无法正常工作。
通过使用这个库:https://github.com/JoeDawson/youtube
你能帮我解决这个问题吗?
代码:
class VideoController extends BaseController {
public function __construct(){
}
public function store(Request $request){
$video = Youtube::upload($request->file("video")->getPathName(), [
'title' => 'My Video',
'description' => 'This video is uploaded through API.',
'tags' => ['api', 'youtube'],
]);
return $this->sendResponse($video);
}
}
根据该包的文档,您需要执行这些步骤,因为您可能遇到 refresh_token 的问题(我猜您没有任何令牌在您的数据库中,必须在登录后创建 google)
重要的是,在您开始上传视频之前,您已经确认您的数据库中有一个 refresh_token,否则这些步骤必须有所帮助。
1- 删除 youtube_access_tokens table 中的所有标记。
2- 在 youtube.php
中启用路由
3- Re-authenticate 与 Google
4- 检查您的 youtube_access_tokens table 并找到最近的 令牌 。
5- 检查令牌并确保 refresh_token 存在。
6- 在 config/youtube.php
简而言之,用于创建令牌您需要访问您的 Google console 并添加您的 URL 作为回调(本地主机)。 然后在您的应用程序中,访问 http://localhost:8000/youtube/auth - 您将被重定向到 Google 并被要求登录。这是您获得令牌的时间,然后您可能不会再看到该错误!