执行YouTube Data API PHP快速入门时的令牌重置问题求助
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 thetoken.jsonfile there. Just delete it. - If you don't see it, open up
quickstart.phpand look for the line that defines$tokenPath. It usually looks like this:
The path here tells you exactly where the token file is stored. Go to that location and delete the file.$tokenPath = 'token.json';
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:
- Copy the link, paste it into your browser, and complete the Google login/authorization steps.
- Copy the authorization code Google gives you.
- 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

