Ios 如何上传未在Youtube中列出的具有隐私设置的视频
我正在用这个代码上传youtube上的视频Ios 如何上传未在Youtube中列出的具有隐私设置的视频,ios,youtube,Ios,Youtube,我正在用这个代码上传youtube上的视频 - (void)sendVideoFileMetadata:(NSDictionary *)videoMetadata error:(NSError **)error { [self logDebug:@"Sending file info..."]; NSString *category = videoMetadata[kDDYouTubeVideoMetadataCategoryKe
- (void)sendVideoFileMetadata:(NSDictionary *)videoMetadata
error:(NSError **)error
{
[self logDebug:@"Sending file info..."];
NSString *category = videoMetadata[kDDYouTubeVideoMetadataCategoryKey];
NSString *keywords = videoMetadata[kDDYouTubeVideoMetadataKeywordsKey];
NSString *title = videoMetadata[kDDYouTubeVideoMetadataTitleKey];
NSString *desc = videoMetadata[kDDYouTubeVideoMetadataDescriptionKey];
NSString *xml = [NSString stringWithFormat:
@"<?xml version=\"1.0\"?>"
@"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"
@"<media:group>"
@"<media:title type=\"plain\">%@</media:title>"
@"<media:description type=\"plain\">%@</media:description>"
@"<media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">%@</media:category>"
@"<media:keywords>%@</media:keywords>"
@"<media:privacyStatus>unlisted</media:privacyStatus>"
@"</media:group>"
@"</entry>", title, desc, category, keywords];
NSURL *url = [NSURL URLWithString:@"https://gdata.youtube.com/action/GetUploadToken"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"GoogleLogin auth=\"%@\"", self.authorizationToken] forHTTPHeaderField:@"Authorization"];
[request setValue:@"2" forHTTPHeaderField:@"GData-Version"];
[request setValue:@"unlisted" forHTTPHeaderField:@"privacyStatus"];
[request setValue:[NSString stringWithFormat:@"key=%@", self.developerKey] forHTTPHeaderField:@"X-GData-Key"];
[request setValue:@"application/atom+xml; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%u", (unsigned int)xml.length] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:[xml dataUsingEncoding:NSUTF8StringEncoding]];
self.responseData = [[NSMutableData alloc] init];
self.currentConnection = [DDURLConnection connectionWithRequest:request delegate:self];
[self.currentConnection setType:DDYouTubeUploaderConnectionTypePrepare];
// Create error if there were
// problems creating a connection
if (!self.currentConnection)
{
*error = [self createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
description:@"Cannot create connection to YouTube."];
}
}
- (BOOL)uploadVideoFile:(NSURL *)fileURL
error:(NSError **)error
{
NSString *boundary = @"AbyRvAlG";
NSString *nextURL = @"http://www.youtube.com";
NSData *fileData = [NSData dataWithContentsOfFile:[fileURL relativePath]];
_videoFileLength = [fileData length];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?nexturl=%@", self.uploadURLString, nextURL]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
NSMutableString *bodyString = [NSMutableString new];
// Add token
[bodyString appendFormat:@"\r\n--%@\r\n", boundary];
[bodyString appendString:@"Content-Disposition: form-data; name=\"token\"\r\n"];
[bodyString appendString:@"Content-Type: text/plain\r\n\r\n"];
[bodyString appendFormat:@"%@", self.uploadToken];
// Add file name
[bodyString appendFormat:@"\r\n--%@\r\n", boundary];
[bodyString appendFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", [fileURL lastPathComponent]];
[bodyString appendFormat:@"Content-Type: application/octet-stream\r\n\r\n"];
[bodyString appendFormat:@"privacyStatus: unlisted\r\n\r\n"];
// Create the data
[body appendData:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:fileData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// Set the body
[request setHTTPBody:body];
// Create the connection
self.responseData = [[NSMutableData alloc] init];
self.currentConnection = [DDURLConnection connectionWithRequest:request delegate:self];
[self.currentConnection setType:DDYouTubeUploaderConnectionTypeUpload];
if (!self.currentConnection)
{
*error = [self createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
description:@"Cannot create connection to YouTube."];
return NO;
}
return YES;
}
-(void)sendVideoFileMetadata:(NSDictionary*)videoMetadata
错误:(n错误**)错误
{
[自日志调试:@“发送文件信息…”;
NSString*category=videoMetadata[kddyoutubevideomedatacategorykey];
NSString*keywords=videoMetadata[kddyoutubevideomedatakeywordskey];
NSString*title=视频元数据[KDDYOUTUBEVIDEOMataTitleKey];
NSString*desc=视频元数据[KDDYOUTUBEVIDEOMataDescriptionKey];
NSString*xml=[NSString stringWithFormat:
@""
@""
@""
@"%@"
@"%@"
@"%@"
@"%@"
@“未上市”
@""
@“”、标题、说明、类别、关键字];
NSURL*url=[NSURL URLWithString:@”https://gdata.youtube.com/action/GetUploadToken"];
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:url];
[请求设置HttpMethod:@“POST”];
[request setValue:[NSString stringWithFormat:@“GoogleLogin auth=\“%@\”,self.authorizationToken]forHTTPHeaderField:@“Authorization”];
[请求设置值:@“2”用于HttpHeaderField:@“GData版本”];
[请求设置值:@“未列出”用于HttpHeaderField:@“privacyStatus”];
[request setValue:[NSString stringWithFormat:@“key=%@”,self.developerKey]用于HttpHeaderField:@“X-GData-key”];
[RequestSetValue:@“应用程序/atom+xml;字符集=UTF-8”用于HttpHeaderField:@“内容类型”];
[request setValue:[NSString stringWithFormat:@“%u”,(unsigned int)xml.length]forHTTPHeaderField:@“内容长度”];
[请求setHTTPBody:[xml数据使用编码:NSUTF8StringEncoding]];
self.responseData=[[NSMutableData alloc]init];
self.currentConnection=[ddurlConnectionConnectionWithRequest:request委托:self];
[self.currentConnection设置类型:DDYouTubeUploaderConnectionTypePrepare];
//如果存在错误,则创建错误
//创建连接时遇到的问题
如果(!self.currentConnection)
{
*错误=[self-createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
描述:@“无法创建到YouTube的连接。”];
}
}
-(BOOL)上传视频文件:(NSURL*)文件URL
错误:(n错误**)错误
{
NSString*边界=@“AbyRvAlG”;
NSString*nextURL=@”http://www.youtube.com";
NSData*fileData=[NSData dataWithContentsOfFile:[fileURL relativePath]];
_videoFileLength=[fileData长度];
NSURL*url=[NSURL URLWithString:[NSString stringWithFormat:@“%@?nexturl=%@”,self.uploadURLString,nexturl]];
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:url];
[请求设置HttpMethod:@“POST”];
[request setValue:[NSString stringWithFormat:@“多部分/表单数据;边界=%@”,边界]用于HttpHeaderField:@“内容类型”];
NSMutableData*正文=[NSMutableData];
NSMutableString*bodyString=[NSMutableString new];
//添加令牌
[bodyString appendFormat:@“\r\n--%@\r\n”,边界];
[bodyString appendString:@“内容处置:表单数据;名称=\”标记\“\r\n”];
[bodyString appendString:@“内容类型:text/plain\r\n\r\n”];
[bodyString appendFormat:@“%@”,self.uploadToken];
//添加文件名
[bodyString appendFormat:@“\r\n--%@\r\n”,边界];
[bodyString appendFormat:@“内容处置:表单数据;名称=\”文件名=\“%@\”\r\n,[fileURL lastPathComponent]];
[bodyString appendFormat:@“内容类型:应用程序/八位字节流\r\n\r\n”];
[bodyString appendFormat:@“privacyStatus:未列出\r\n\r\n”];
//创建数据
[body appendData:[bodyString数据使用编码:NSUTF8StringEncoding];
[body appendData:[NSData dataWithData:fileData]];
[body appendData:[[NSString stringWithFormat:@“\r\n--%@--”,边界]数据使用编码:NSUTF8StringEncoding];
//定身
[请求setHTTPBody:body];
//创建连接
self.responseData=[[NSMutableData alloc]init];
self.currentConnection=[ddurlConnectionConnectionWithRequest:request委托:self];
[self.currentConnection setType:DDYouTubeUploaderConnectionTypeUpload];
如果(!self.currentConnection)
{
*错误=[self-createErrorWithCode:DDYouTubeUploaderErrorCodeCannotCreateConnection
描述:@“无法创建到YouTube的连接。”];
返回否;
}
返回YES;
}
这个工作非常好,
但问题是视频上传为Public
,我想上传为未列出的
我尝试了这么多标签,但都没有成功。
已使用,
-隐私
-私人身份
有人能告诉我应该在哪里添加标签以及标签是什么吗?
代码片段将更有帮助。只需通过添加
<yt.accesscontrol>
它将上传未上市的视频
NSString *xml = [NSString stringWithFormat:
@"<?xml version=\"1.0\"?>"
@"<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"
@"<media:group>"
@"<media:title type=\"plain\">%@</media:title>"
@"<media:description type=\"plain\">%@</media:description>"
@"<media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">%@</media:category>"
@"<media:keywords>%@</media:keywords>"
@"</media:group>"
@"<yt:accessControl action='list' permission='denied'/>"
@"</entry>", title, desc, category, keywords];
NSString*xml=[nsstringwithformat:
@""
@""
@""
@"%@"
@"%@"
@"%@"
@"%@"
@""
@""
@“”、标题、说明、类别、关键字];