使用Next Auth集成Google Provider时出现youtube.readonly权限无效问题
解决NextAuth集成Google Provider时youtube.readonly权限无效的问题
问题原因
Google OAuth的YouTube相关权限必须使用完整的Scope URI,直接写简写的youtube.readonly会被API判定为无效权限。
修复步骤
修正NextAuth配置中的Scope
将scope参数替换为完整的URI形式,同时保留基础权限:import NextAuth from 'next-auth'; import GoogleProvider from 'next-auth/providers/google'; import type { NextAuthOptions } from 'next-auth'; export const authOptions: NextAuthOptions = { providers: [ GoogleProvider({ clientId: process.env.ClientId, clientSecret: process.env.ClientSecret, authorization: { params: { // 使用完整的YouTube只读权限Scope URI scope: 'openid email profile https://www.googleapis.com/auth/youtube.readonly', }, }, }), ], }; export default NextAuth(authOptions);检查Google Cloud Console配置
- 确认已在Google Cloud Console中启用YouTube Data API v3
- 若应用面向外部用户,需在OAuth同意屏幕中添加该完整Scope并完成审核(内部测试应用可跳过审核直接使用)
验证
修改配置后重新授权登录,再调用YouTube API时就不会出现invalid=[youtube.readonly]的错误提示了。
内容的提问来源于stack exchange,提问作者nikolay.akhmetyanov
相关产品推荐
相关产品推荐

