【问题标题】:Alamofire with YouTube API Issues (Swift 3)带有 YouTube API 问题的 Alamofire (Swift 3)
【发布时间】:2017-03-14 07:19:23
【问题描述】:

我在将旧的 Alamofire 代码转换为新的 Swift 3 版本时遇到了一些问题。我收到错误:调用中的额外参数“方法”

//        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)

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: swift youtube-api alamofire


    【解决方案1】:

    问题不在于 method 参数,而在于您可以设置为 URLEncoding.default 的编码,因为标头为 nil,所以我猜您不需要它

    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
    })
    

    顺便说一句,您可以将 responseData 改回您已有的内容

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多