首页 > 解决方案 > YouTube 数据 API 错误 403 权限不足

问题描述

我正在使用需要访问用户的 YouTube 订阅的 Swift 开发 IOS 应用程序。在 Google Cloud Platform 上添加我需要的所有范围并在 Firebase 中实现 GoogleSignIn 之后。我登录(GIDSignInButton),然后在发出此请求后收到如下所示的错误:

https://www.googleapis.com/youtube/v3/subscriptions?part=snippet%2CcontentDetails&mine=true&key=\(apiKey)&access_token=\(Access_Token).

Access_Token 是我打电话后得到的:

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?){
    user.authentication.accessToken
....}

我得到的错误:

 ["error": {
        code = 403;
        errors =     (
                    {
                domain = global;
                message = "Insufficient Permission";
                reason = insufficientPermissions;
            }
        );
        message = "Request had insufficient authentication scopes.";
        status = "PERMISSION_DENIED";
    }]

在 App Delegate 中,我设置了这个:

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID

标签: iosswiftgoogle-cloud-platformyoutube-data-apigoogle-signin

解决方案


我遇到了同样的问题,如果我没记错的话,它发生在我的 OAuth 同意验证状态未经验证时。我所做的工作是,除了在 Google 仪表板中提供范围之外,我还在登录前以编程方式添加了它们。

GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/youtube.upload")
GIDSignIn.sharedInstance().signIn()

推荐阅读