如何在iOS应用中获取YouTube数据?

时间:2017-07-12 20:19:42

标签: ios swift

我正在尝试构建一个包含一些YouTube视频的应用。 我正在使用YouTube的API并使用Alamofire访问数据,但我的数据检索尝试导致以下错误:

{
    error =
    {
        code = 404;

        errors =({

                domain = "youtube.playlist";

                location = channelId;

                locationType = parameter;

                message = "Channel not found.";

                reason = channelNotFound;

            }

        );
        message = "Channel not found.";
    };
}

这是我viewDidLoad

的内容
let API_KEY = "*********"
let UPLOADS_PLAYLIST_ID = "PL28aSZBaDzoatmISten8xeFPPuva7l8s5"
let CHANNEL_ID = "PL28aSZBaDzoatmISten8xeFPPuva7l8s5"
let parameters =["part":"snippet","channelId":CHANNEL_ID,"playListId":UPLOADS_PLAYLIST_ID,"key":API_KEY]

Alamofire.request("https://www.googleapis.com/youtube/v3/playlists", parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in

            if let JSON = response.result.value 
            {
                print(JSON)
            }
}

1 个答案:

答案 0 :(得分:0)

首先转到youtube并找到频道名称,然后输入

 let CHANNEL_ID = "properchannel"