我通过 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/