英文:
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得到了一个提示
我必须添加这两行。不知道"setPrompt"函数是存在的!
$client->setPrompt('consent');
$client->setAccessType('offline');
英文:
So finally got a hint from ChatGPT
I had to add these two lines. Didn't know the "setPromt" function existed!
$client->setPrompt('consent');
$client->setAccessType('offline');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论