Search code examples
iphoneiosobjective-cgoogle-api-objc-client

Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:]


i am trying to upload a video on youtube using Google APIs Client Library for Objective-C, I using given below code but it is keep on giving me this error, i tried to run my account on youtube example project here again it gives that same error.

Can any one guide me where is the problem. I check YouTube Data API v3 is on in services page.

*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:], /Volumes/data/Work/test/DLNew/DL/google-api-objectivec-client-read-only/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399
2013-08-30 14:28:31.399 [1250:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unexpected response data (uploading to the wrong URL?)'

i check the code of GTMHTTPUploadFetcher class it is crashing the app on this link

`#if DEBUG
  // The initial response of the resumable upload protocol should have an
  // empty body
  //
  // This assert typically happens because the upload create/edit link URL was
  // not supplied with the request, and the server is thus expecting a non-
  // resumable request/response.
  NSAssert([[self downloadedData] length] == 0,
                    @"unexpected response data (uploading to the wrong URL?)");
 #endif

.

 NSString *path              = [[NSUserDefaults standardUserDefaults] objectForKey:@"MOVIEPATH"];
NSString *filename = [path lastPathComponent];
NSString *mimeType = [self MIMETypeForFilename:filename defaultMIMEType:@"video/mp4"];

NSError *eel=nil;

NSFileHandle *handle        = [NSFileHandle fileHandleForReadingFromURL:[NSURL URLWithString:path] error:&eel];
NSLog(@"error is  %@",eel);
if (!handle)
{
    NSLog(@"Failed to open file for reading");
    return;
}



GTLServiceYouTube *service      = [[GTLServiceYouTube alloc] init];
service.authorizer              = self.gTMOAuth2Authentication;

GTLUploadParameters *params     = [GTLUploadParameters uploadParametersWithFileHandle:handle MIMEType:mimeType];

GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title                   = @"Test title";
snippet.descriptionProperty     = @"Test description";
snippet.tags                    = [NSArray arrayWithObjects:@"TestOne", @"TestTwo" ,nil];
snippet.categoryId              = @"17";

GTLYouTubeVideoStatus *status   = [GTLYouTubeVideoStatus object];
status.privacyStatus            = @"private";

GTLYouTubeVideo *video2          = [GTLYouTubeVideo object];
video2.snippet                   = snippet;
video2.status                    = status;

GTLQueryYouTube *query          = [GTLQueryYouTube queryForVideosInsertWithObject:video2 part:@"snippet,status" uploadParameters:params];



// Perform the upload
GTLServiceTicket *ticket        = [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
{
    if (error)
    {
        NSLog(@"ERROR: %@", error);
        return;
    }

    NSLog(@"SUCCESS! %@; %@;", ticket, object);
}];

ticket.uploadProgressBlock = ^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength)
{
    NSLog(@"%lld / %lld", numberOfBytesRead, dataLength);
};

----------

The problem was i was logging from a new gmail account so i need to login in youtube site and need to create a channel before i can upload video to youtube. So now i can upload videos after creating a youtube channel. but How can i handle this scenario for other users, any idea


Solution

  • The problem was i was logging from a new gmail account so i need to login in youtube site and need to create a channel before i can upload video to youtube. So now i can upload videos after creating a youtube channel. but How can i handle this scenario for other users, any idea