编辑:经常检查这个,当我或其他人帮我解决时,将标记为已解决!
我正在尝试通过Swift将YouTube视频上传到YouTube的REST API,但我很难搞清楚要做什么.我目前有一个有效的GET请求.
我对如何构造POST请求URL以及文件位置在请求中的位置感到困惑.另外我想我应该使用可重新上传的协议?
我已经在各种API和文档中苦苦挣扎了2天,感到绝望.
这是我的GET请求的工作代码.
func getRequestVideoInfo(){
// Set up your URL
let youtubeApi = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails%2C+snippet%2C+statistics&id=AKiiekaEHhI&key=" + apiKey
let url = NSURL(string: youtubeApi)
// Create your request
let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in
do {
if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? [String : AnyObject] {
print("Response from YouTube: \(jsonResult)")
}
}
catch {
print("json error: \(error)")
}
})
// Start the request
task.resume()
}
Run Code Online (Sandbox Code Playgroud)