Tec*_*ain 6 xcode ios youtube-data-api swift
我想从我自己的应用程序上传Youtube上的视频,并在杀死应用程序后甚至在后台模式下恢复上传.我试过这个链接,但这是一个MacApp而不是iOS应用程序.此外,当我运行它时,它在pod文件中说NSURLSession在10.9或更新版本中可用.所以它似乎对我不起作用.
https://github.com/google/google-api-objectivec-client-for-rest/tree/master/Examples
任何人都可以指导我如何在一个更好,也许是一个简单的例子中实现这一目标.
编辑: 我已尝试下面的代码,我得到以下错误.请帮助我解决问题.
func postVideoToYT(videoData: Data, token: String,title:String,innoId:Int,videoTags:String,callback: @escaping (Bool) -> Void) {
do {
let headers = ["Authorization": "Bearer \(token)"]
upload(multipartFormData: { multipartFormData in
multipartFormData.append("{'snippet':{'title' : '\(title)','description': 'abc'}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "snippet", mimeType: "application/json")
multipartFormData.append("{'status' : {'privacyStatus':'private'}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "status",mimeType: "application/json")
multipartFormData.append(videoData, withName: "video", fileName: "video.mov", mimeType: "application/octet-stream")
}, usingThreshold: 1, to: URL(string: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet&status")!, method: .post, headers: headers, encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
print("Post video to url --->\(response)")
if let json = response.result.value as? [String : Any] {
let videoId = json["id"] as? String ?? ""
/* self.delayWithSeconds(1, completion: {
self.addVideo(innoId: innoId, videoKey:videoId, shortDesc: title, tagIds: videoTags)
})*/
}
callback(true)
}
upload.uploadProgress(closure: { (progress) in
print(progress)
// self.progressView.progress = Float(progress.fractionCompleted)
//self.progressLabel.text = "\(( Int(progress.fractionCompleted * 100)))%"
})
break
case .failure(_):
callback(false)
break
}
})
}
catch {
print("Catch error")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
636 次 |
| 最近记录: |