ios - YouTube Data Api Swift:通过隐私状态和标签将视频分享到 YouTube
问题描述
我的应用程序中有一个分享到 youtube 的功能。我也允许用户选择隐私状态。我可以上传带有标题和说明的视频。我无法设置视频的隐私状态和主题标签。我尝试了隐私状态,但它不起作用。我不确定如何为视频添加标签。
这是我将视频上传到 YouTube 的功能:
// MARK: Share to Platforms
func postVideoToYouTube(token: String, callback: @escaping (Bool) -> Void) {
let headers = ["Authorization": "Bearer \(token)"]
do {
videoData = try Data.init(contentsOf: videoForThirdParty!)
} catch {
print("cannot get contents of video")
}
var captionText: String?
if let captionTextStuff = captionTextField.text {
captionText = captionTextStuff
}
upload(
multipartFormData: { multipartFormData in
multipartFormData.append("{'snippet':{'title' : '\(captionText!)' , 'description': 'This video was made with Vloggle'}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"snippet", mimeType: "application/json")
// This is where I set the privacy status:
multipartFormData.append("{'status':{'privacyStatus' : 'private'}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName :"status", mimeType: "application/json")
multipartFormData.append(self.videoData!, withName: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
}, usingThreshold: UInt64.init(),
to: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet",
headers: headers,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON(completionHandler: { (response) in
print(response)
callback(true)
})
case .failure(_):
callback(false)
}
})
}
解决方案
推荐阅读
- html - 让 div 向左而不是向右生长
- ios - JsonEncoder 总是返回空数组
- java - 使用 spark-submit 和 java -cp 运行 spark 应用程序有什么区别?
- orocrm - ORO CRM:在 config.yml 中找不到捆绑资源
- xamarin.forms - 在 PopAsync() 之后,Xamarin.forms 选项卡式页面未在 ios 中显示
- jquery - 带有多余边距顶部的 jQuery 移动面板
- javascript - 在构造函数中获取数据
- javascript - Next.js:带状态的 Router.push
- vba - 删除字符串中的空行
- android - 处理 android 键盘上的搜索按钮 - 科尔多瓦应用程序