I'm working on an info app about a singer. Now I have to integrate her YouTube videos, playlists and comments on the videos, but I found no appropriate way to do it. This could be JSON returning a value, or just simple API that lets you receive info about a particular video on YouTube.
Asked
Active
Viewed 2,095 times
1 Answers
0
Use the videos/list
endpoint of the YouTube v3 API with these parameters:
part
-> snippet
id
-> The video's video_id, example: jCHE0Tjw6MA
HTTP GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=jCHE0Tjw6MA&key={YOUR_API_KEY}
Swift:
let task = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=jCHE0Tjw6MA&key={YOUR_API_KEY}")!, completionHandler: { (data, response, error) -> Void in
do {
if let parsedResponse: [String : AnyObject] = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? [String : AnyObject] {
let description = parsedResponse["items"]![0]["description"] // the first item's decsription
print(description) // "███████████████████▌HD / HQ Official Music Video ███████████████████▌\r\n\r\nReal Life - Send Me An Angel\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nreal life send me an angel official music video hq hd 1983 89 lyrics live cover remix extended original"
}
}
catch {
print("json error: \(error)")
}
})
task.resume()

JAL
- 41,701
- 23
- 172
- 300