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

使用Next Auth集成Google Provider时出现youtube.readonly权限无效问题

解决NextAuth集成Google Provider时youtube.readonly权限无效的问题

问题原因

Google OAuth的YouTube相关权限必须使用完整的Scope URI,直接写简写的youtube.readonly会被API判定为无效权限。

修复步骤

  1. 修正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);
    
  2. 检查Google Cloud Console配置

    • 确认已在Google Cloud Console中启用YouTube Data API v3
    • 若应用面向外部用户,需在OAuth同意屏幕中添加该完整Scope并完成审核(内部测试应用可跳过审核直接使用)

验证

修改配置后重新授权登录,再调用YouTube API时就不会出现invalid=[youtube.readonly]的错误提示了。

内容的提问来源于stack exchange,提问作者nikolay.akhmetyanov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 00:12:43