gpt4 book ai didi

Swift - 如何上传视频到 youtube 不公开?

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:39 24 4
gpt4 key购买 nike

我从我的应用程序将视频上​​传到 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 {

}
}

最佳答案

隐私必须与代码段一起传递

"{'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 {

}
}

关于Swift - 如何上传视频到 youtube 不公开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48781588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com