YouTube API的OATH访问令牌

huangapple go评论105阅读模式
英文:

YouTube Api OATH access token

问题

我想制作一个机器人,可以将硬盘上的视频上传到YouTube。我已经编写了代码,但出现了问题。我必须手动通过登录到Google帐户来进行授权,这会给我提供一个仅有效1小时的访问令牌。现在的问题是机器人无法登录到帐户,我也无法在一小时后使用访问令牌。我听说过刷新令牌,但不太清楚它的工作原理,你能帮我解决这个问题吗?完美的情况是通过“Client_id”和“Secret_Key”获得访问令牌(我不应该需要登录)

$client = new Google_Client();
$client->setClientId(YOUTUBE_CLIENT_ID);
$client->setClientSecret(YOUTUBE_CLIENT_SECRET);
$client->setAccessToken(???);
英文:

I want to make a bot that will upload the videos from hard disk to YouTube. I have written the code already but there is a problem. I have to make the authorization manually by logging in to the Google account which gives me an access token, valid for only 1 hour. Now the trouble is the bot wont be able to login to the account and I am unable to use the access token after an hour. I heard about the refresh token but not sure how it works, can you help me with this? The perfect scenario would be having the access token through "Client_id" and "Secret_Key" (I should not have to login)

$client = new Google_Client();
$client->setClientId(YOUTUBE_CLIENT_ID);
$client->setClientSecret(YOUTUBE_CLIENT_SECRET);
$client->setAccessToken(???);

答案1

得分: 0

好的,理解了。以下是翻译的部分:

最终从ChatGPT得到了一个提示 YouTube API的OATH访问令牌
我必须添加这两行。不知道"setPrompt"函数是存在的!

$client->setPrompt('consent');
$client->setAccessType('offline');
英文:

So finally got a hint from ChatGPT YouTube API的OATH访问令牌
I had to add these two lines. Didn't know the "setPromt" function existed!

$client->setPrompt('consent');
$client->setAccessType('offline');

huangapple
  • 本文由 发表于 2023年2月27日 17:27:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578691.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定