2016-08-10 3 views
1

ich ein Video auf youtube bin Hochladen mit diesem Code ..Wie Video mit Privacy laden in Youtube nicht angegeben Einstellung

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

Diese funktionierend, Aber die Frage ist Video Public hochgeladen, ich will es zum Hochladen als Unlisted.
Ich habe so viele Tag versucht, aber nicht in der Lage, Erfolg zu bekommen.
gebraucht,
- privacy
- privacystatus

Kann mir jemand mitteilen, wo soll ich den Tag und was ist der Tag hinzufügen?
Code-Snippet wird hilfreicher sein.

Antwort

2

Gerade xml aktualisiert durch Hinzufügen

<yt.accesscontrol> 

und es wird Video als nicht notierte

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]; 
uplaoad
Verwandte Themen