Search code examples
swiftyoutube-apialamofire

Alamofire with YouTube API Issues (Swift 3)


I'm having some trouble converting my old Alamofire code to the new Swift 3 version. I'm getting the error: Extra argument 'method' in call

//        Fetch the videos dynamiclly through the YouTube Data API

   Alamofire.request("https://www.googleapis.com/youtube/v3/playlistItems", method: .get, parameters: ["part":"snippet", "playlistId":UPLOADS_PLAYLIST_ID,"key":API_KEY], encoding: ParameterEncoding.URL, headers: nil)

Can someone help me with this?


Solution

  • The problem is not in the method argument but in the encoding which you can set to URLEncoding.default also since the header is nil then i guess you dont need it

    let parameters: Parameters = ["part":"snippet",
                                    "playlistId":UPLOADS_PLAYLIST_ID,
                                    "key":API_KEY]
    let url = "https://www.googleapis.com/youtube/v3/playlistItems"
    
    Alamofire.request(url,
                      method: .get,
                      parameters: parameters,
                      encoding: URLEncoding.default)
       .responseData(completionHandler: { response in
        //do what you want
    })
    

    by the way you can change responseData back to what you already have