You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行YouTube Data API PHP快速入门时的令牌重置问题求助

Fixing the "refresh token must be passed in" Error for YouTube API PHP Quickstart

First off, don't worry—this is a super common mishap when working with OAuth flows, and it's easy to fix. Here's exactly what you need to do:

1. Locate and Delete the Existing Token File

The YouTube PHP quickstart stores your authorization token in a file called token.json by default. This file is what's causing the error now because it's incomplete (you didn't finish the auth flow the first time).

  • Check the same directory where you saved quickstart.php—you should see the token.json file there. Just delete it.
  • If you don't see it, open up quickstart.php and look for the line that defines $tokenPath. It usually looks like this:
    $tokenPath = 'token.json';
    
    The path here tells you exactly where the token file is stored. Go to that location and delete the file.

2. Re-Run the Authorization Flow

Once the old token file is gone, run the script again in your terminal:

php quickstart.php

This will generate a new authorization link for you. This time, make sure to:

  1. Copy the link, paste it into your browser, and complete the Google login/authorization steps.
  2. Copy the authorization code Google gives you.
  3. Go back to your terminal, paste the code when prompted, and press enter.

The script will now create a new, valid token.json file with the full refresh token and access token, and the error should be gone.

Extra Troubleshooting Tip (Just in Case)

If you still run into issues after deleting the token file, double-check your OAuth client ID setup:

  • Make sure you created a Desktop app type client ID (since this is a local script).
  • Ensure the redirect URI is set to http://localhost (this matches the quickstart's default configuration).

内容的提问来源于stack exchange,提问作者Žan Dvoršak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:24:10