1

我正在尝试将在我的应用中拍摄的视频上传到 YouTube。我已将标题、用户名、密码、电影路径、长度、关键字和类别与我的应用程序密钥联系起来。然而,当我尝试上传时,我收到以下消息。

2012-12-02 21:29:33.235 我的小世界应用程序 [12790:907] * -GDataServiceBase fetchObjectWithURL:objectClass:objectToPost:ETag:httpMethod:delegate:didFinishSelector:completionHandler:retryInvocationValue:ticket:, /Users/nilesh 中的断言失败/gdata-objectivec-client-read-only/Source/BaseClasses/GDataServiceBase.m:549 2012-12-02 21:29:33.238 my little world app[12790:907] *由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:'需要 GTMHTTPUploadFetcher'

这是我用来尝试上传的代码。

- (IBAction)publish: (id) sender;{

    self.mProgressView.hidden =NO;

    NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
    NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectorya = [pathsa objectAtIndex:0];
    //Get a full path to the image in the documents directory.
    NSString *fullPatha = [documentsDirectorya stringByAppendingPathComponent:audioName];
    NSError *error = nil;
    NSDictionary *attributes = [[NSFileManager defaultManager]
                                attributesOfItemAtPath:fullPatha error:&error];

    if (!error) {
        NSNumber *size = [attributes objectForKey:NSFileSize];
    }

    NSString *devKey = @"xxxxxx";

    GDataServiceGoogleYouTube *service = [self youTubeService];
    [service setYouTubeDeveloperKey:devKey];

    NSString *username = self.accountView.text;
  NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
    NSData *data = [NSData dataWithContentsOfFile:fullPatha];
    NSString *filename = [pictureDictionary4 objectForKey:@"photoVideokey"];

    // gather all the metadata needed for the mediaGroup
    NSString *titleStr =self.movieNameField.text;
    GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

    NSString *categoryStr = self.catagoryField.text;
    GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
    [category setScheme:kGDataSchemeYouTubeCategory];

    NSString *descStr = self.descpView.text;
    GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

    NSString *keywordsStr = self.tagsField.text;
    GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

    BOOL isPrivate = NO;

    GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
    [mediaGroup setMediaTitle:title];
    [mediaGroup setMediaDescription:desc];
    [mediaGroup addMediaCategory:category];
    [mediaGroup setMediaKeywords:keywords];
    [mediaGroup setIsPrivate:isPrivate];

    NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fullPatha
                                               defaultMIMEType:@"video/mp4"];

    // create the upload entry with the mediaGroup and the file data
    GDataEntryYouTubeUpload *entry;
    entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                          data:data
                                                      MIMEType:mimeType
                                                          slug:filename];

    SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
    [service setServiceUploadProgressSelector:progressSel];

    GDataServiceTicket *ticket;
    ticket = [service fetchEntryByInsertingEntry:entry
                                      forFeedURL:url
                                        delegate:self
                               didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

    [self setUploadTicket:ticket];

    NSLog(@"%@",length.text);
    NSLog(@"%@",number.text);
     NSLog(@"%@",accountView.text);
     NSLog(@"%@",tagsField.text);
     NSLog(@"%@",catagoryField.text);
     NSLog(@"%@",movieNameField.text); 
     NSLog(@"%@",descpView.text);
     NSLog(@"%@",PasswordDisplayField.text);
     NSLog(@"%@",ViewingField.text);

    NSLog(@"%@",username);
    NSLog(@"%@",url);
    NSLog(@"%@",filename);
    NSLog(@"%@",titleStr);
    NSLog(@"%@",category);
    NSLog(@"%@",categoryStr);
    NSLog(@"%@",descStr);
    NSLog(@"%@",desc);
    NSLog(@"%@",keywords);
     NSLog(@"%@",keywords);
     NSLog(@"%@",keywordsStr);



}





    - (GDataServiceGoogleYouTube *)youTubeService {

        static GDataServiceGoogleYouTube* service = nil;

        if (!service) {
            service = [[GDataServiceGoogleYouTube alloc] init];


            [service setServiceShouldFollowNextLinks:YES];
            [service setIsServiceRetryEnabled:YES];
        }

        // update the username/password each time the service is requested
        NSString *username = [accountView text];
        NSString *password = [PasswordDisplayField text];

        if ([username length] > 0 && [password length] > 0) {
            [service setUserCredentialsWithUsername:username
                                           password:password];
        } else {
            // fetch unauthenticated
            [service setUserCredentialsWithUsername:nil
                                           password:nil];
        }

        NSString *devKey =  @"AI39si5rnzA1o82wzQj_kFFJBQRNEPv29OKD9hx6RxLPzvacvfvLFi_uI9eNj0uq8Cul8VQnBbDs4CAvq7ViKq-RnVCgh3OVBQ";
        [service setYouTubeDeveloperKey:devKey];

        return service;
    }

    // progress callback
    - (void)ticket:(GDataServiceTicket *)ticket
hasDeliveredByteCount:(unsigned long long)numberOfBytesRead
ofTotalByteCount:(unsigned long long)dataLength {

    [mProgressView setProgress:(double)numberOfBytesRead / (double)dataLength];
}

    // upload callback
    - (void)uploadTicket:(GDataServiceTicket *)ticket
finishedWithEntry:(GDataEntryYouTubeVideo *)videoEntry
error:(NSError *)error {
    if (error == nil) {
        // tell the user that the add worked
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uploaded!"
                                                        message:[NSString stringWithFormat:@"%@ succesfully uploaded",
                                                                 [[videoEntry title] stringValue]]
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];

        [alert show];

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                        message:[NSString stringWithFormat:@"Error: %@",
                                                                 [error description]]
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];

        [alert show];

    }
    [mProgressView setProgress: 0.0];

    [self setUploadTicket:nil];
}

#pragma mark -
#pragma mark Setters

    - (GDataServiceTicket *)uploadTicket {
        return mUploadTicket;
    }

    - (void)setUploadTicket:(GDataServiceTicket *)ticket {

        mUploadTicket = ticket;
    }

我真的很感激这方面的一些方向。谢谢

4

2 回答 2

1

听起来您缺少Google Toolbox for Mac - HTTP Fetcher依赖项?

一般来说,如果您在专门的问题跟踪器讨论组中提问,您可能会在特定于 Objective-C GData 客户端库的问题上获得更多帮助,因为这实际上是一个实现问题,而不是一般的 YouTube API 问题。

于 2012-12-03T15:37:27.583 回答
0

我终于通过将所有正确的 .h 文件添加到我的应用程序并导入它们(包括正确的 GTMHTTPUploadFetcher 文件)使这部分工作。谢谢您的帮助。

于 2013-06-27T16:42:34.957 回答