我从我的应用上传视频到youtube。但它现在是公开的。
我的问题是如何将视频上传为不公开?
这是我的上传功能
func postVideoToYT(videoUrl: URL, token: String,title:String,innoId:Int,videoTags:String,callback: @escaping (Bool) -> Void) {
do {
let headers = ["Authorization": "Bearer \(token)"]
let videoData = try Data(contentsOf: videoUrl)
upload(multipartFormData: { multipartFormData in
multipartFormData.append("{'snippet':{'title' : '\(title)', 'description': ''}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "snippet", mimeType: "application/json")
multipartFormData.append(videoData, withName: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
}, usingThreshold: 1, to: URL(string: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet")!, 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)
}
break
case .failure(_):
callback(false)
break
}
})
}
catch {
}
}
答案 0 :(得分:0)
隐私必须与摘要一起传递
"{'snippet':{'title' : '\(title)', 'description':' \(description)', 'tags': \(keywords)},'status':{'privacyStatus' : '\(privacyStatus)'}}".data(using: .utf8, allowLossyConversion: false)!
在下面的代码中添加了隐私。
func postVideoToYT(videoUrl: URL, token: String,title:String,innoId:Int,videoTags:String,callback: @escaping (Bool) -> Void) {
do {
let headers = ["Authorization": "Bearer \(token)"]
let videoData = try Data(contentsOf: videoUrl)
upload(multipartFormData: { multipartFormData in
multipartFormData.append("{'snippet':{'title' : '\(title)', 'description':' \(description)', 'tags': \(keywords)},'status':{'privacyStatus' : '\(privacyStatus)'}}".data(using: .utf8, allowLossyConversion: false)!, withName: "snippet", mimeType: "application/json")
multipartFormData.append(videoData, withName: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
}, usingThreshold: 1, to: URL(string: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet")!, 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)
}
break
case .failure(_):
callback(false)
break
}
})
}
catch {
}
}