Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3640

Swift error retrieving data from YouTube API "no value found for key CodingKeys"

$
0
0

I am trying to retrieve the videos from my Youtube Playlist but it throws an error debugDescription: "Cannot get KeyedDecodingContainer -- no value found for key CodingKeys(stringValue: "url", intValue: nil) ("url")", underlyingError: nil))))Here is how my VideoModel is structured

import Alamofireclass VideoModel: ObservableObject {    @Published var videos = [Video]()    init() {        getVideos()    }    func getVideos() {        // Create URL Obj        guard let url = URL(string: "\(Constants.API_URL)/playlistItems") else {            return        }        // Get a decoder        let decoder = JSONDecoder()        decoder.dateDecodingStrategy = .iso8601        // Create URL request        AF.request(            url, parameters: ["part": "snippet", "playlistId": Constants.PLAYLIST_ID, "key": Constants.API_KEY]        )            .validate()            .responseDecodable(of: Response.self, decoder: decoder) { response in                // Check that the call was successful                switch response.result {                case .success:                    break                case .failure(let error):                    // print(error.localizedDescription)                    debugPrint(error)                    return                }                // update  the UI with videos                if let items = response.value?.items {                    DispatchQueue.main.async {                        self.videos = items                     }

How can I fix this? Thank you


Viewing all articles
Browse latest Browse all 3640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>