gpt4 book ai didi

ios - 如何使用YouTube中未列出的“隐私”设置上传视频

转载 作者:行者123 更新时间:2023-12-01 20:05:45 26 4
gpt4 key购买 nike

我正在使用此代码在youtube上上传视频。

- (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;
}

这很好用
但是问题是将视频上传为 Public,我想将其上传为 Unlisted
我尝试了很多标签,但无法成功。
用过的,
-隐私
-privacystatus

谁能告诉我应该在哪里添加标签以及标签是什么?
代码段将更有用。

最佳答案

只需通过添加

<yt.accesscontrol>
更新xml
它将以未列出的
 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];
上传视频

关于ios - 如何使用YouTube中未列出的“隐私”设置上传视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38876890/

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