swift - 列出我的 YouTube 播放列表时出错

标签 swift youtube-api alamofire

我通过 Google 登录 iOS SDK 获得了我的用户访问 token 。 然后我使用以下源代码在 YouTube 中获取我的播放列表:

func listMyPlaylists(completionHandler: @escaping (_ result: Any?, _ error: Error?) -> ())
{
    let url = URL(string: "https://www.googleapis.com/youtube/v3/playlists")!
    let parameters: Parameters = ["part": "id","mine": "true"]
    let headers: HTTPHeaders = ["Authorization": "Bearer " + accessToken, "Content-Type": "application/json"]

    Alamofire.request(url, method: .get, parameters: parameters, encoding: URLEncoding.default, headers: headers).responseJSON { json in

        if let error = json.result.error
        {
            completionHandler(nil, error)
        }
        else
        {
            completionHandler(json.result.value, nil)
        }
    }
}

但是,我收到以下错误。我想念什么?

{
error =     {
    code = 403;
    errors =         (
                    {
            domain = global;
            message = "Insufficient Permission";
            reason = insufficientPermissions;
        }
    );
    message = "Insufficient Permission";
};

最佳答案

这通常发生在您未包括 Youtube API Common request errors 中所述的授权范围时

forbidden (403) - insufficientPermissions The OAuth 2.0 token provided for the request specifies scopes that are insufficient for accessing the requested data.

Youtube scopes 之一你可以使用

https://www.googleapis.com/auth/youtube.force-ssl

关于swift - 列出我的 YouTube 播放列表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41023895/

相关文章:

swift 如何将日期组件转换成双倍以获得上传速度

android - 如何获取 youtube 网址并在我的应用中播放?

swift - 本地 Swift 包在 Xcode 13 中停止工作

api - 我可以在已经在服务器上获得授权的客户端上自动登录用户吗?

youtube - 在使用 YouTube Live Streaming API 时使用基本摄取或避免重复的自定义摄取

ios - 如何在 swift 3 中使用 Alamofire 制作并发送字典数组(JSON 格式)发送到服务器

ios - 关闭向下转换导致 EXC_BAD_INSTRUCTION 错误

ios - 来自 json 的响应字节数组

ios - 可以将类型 '__NSArray0' 的值转换为 'CIRectangleFeature'

swift - 无法扩展枚举;我应该用什么代替?