Validation error in - [GTMHTTPUploadFetcher connectionDidFinishLoading:]

I'm trying to upload a video to YouTube using the Google API client library for Objective-C. I use the code below, but it continues to give me this error, I tried to launch my account in the YouTube example project, here it gives the same error.

Can someone explain to me where the problem is. I check the YouTube v3 data API on the 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 class code GTMHTTPUploadFetcher, it breaks the application at 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 that I registered from a new gmail account, so I need to go to the youtube website and you need to create a channel before I can upload the video to youtube. So, now I can upload the video after creating the YouTube channel. but how can I handle this scenario for other users, any idea

+6
source share
8 answers

The problem was that I registered from a new gmail account, so I need to go to the youtube website and you need to create a channel before I can upload the video to youtube. So, now I can upload the video after creating the YouTube channel. but how can I handle this scenario for other users, any idea

0
source

I faced the same crash and found out a solution. It seems that the client gets this failure also if the underlying request is a bad request but the response information is not explicitly provided (my authorizer is valid and passes the check using the canAuthorize method as Ryan_IRL ).

After looking at the library, I found that setting up the STRIP_GTM_FETCH_LOGGING preprocessor STRIP_GTM_FETCH_LOGGING and enabling logging for HTTPFetcher somewhere in the code

 #if STRIP_GTM_FETCH_LOGGING [GTMHTTPFetcher setLoggingEnabled:YES]; #endif 

Logs are stored in the GTMHTTPDebugLogs folder inside the simulator (something similar to /Users/<username>/Library/Application Support/iPhone Simulator/6.1/Applications/65451CDB-27D6-4BE2-910C-7F22D6A01832/GTMHTTPDebugLogs ). There you can find the full log in HTML format (...).

enter image description here

By clicking on the "request / response log", in my case, the following log was shown.

 Response body: (201 bytes) { "id" : "gtl_1", "error" : { "message" : "Bad Request", "code" : -32602, "data" : [ { "domain" : "youtube.video", "reason" : "invalidTitle", "locationType" : "other", "location" : "body.snippet.title", "message" : "Bad Request" } ] } } 

a bad request was associated with a heading (downloadable video) containing some forbidden characters. The title correction resolved to crash and the video was uploaded correctly. Status 200 in this case, of course ... is disappointing and clearly wrong.

I am also very disappointed with the GTM library and the use of NSAssert for such a situation in the first place.

+6
source

I had the same problem as you (approval error in GTMHTTPUploadFetcher.m: 399) when uploading a video to YouTube. I am posting this in the hope of saving someone else a few minutes of debugging.

It turned out that my problem was the old code that installs the GTLServiceYouTube APIKey, in addition to using OAuth2. Doh.

 GTLServiceYouTube *youtube = [[GTLServiceYouTube alloc] init]; youtube.APIKey = @"-my-simple-api-access-key-"; //<-- offending line [...] youtube.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:kYouTubeClientID clientSecret:kYouTubeClientSecret]; 

The fix was to simply leave APIKey nil using only the OAuth2 authorizer. (APIKey for "easy access to the API", obviously, any hint of both leads to problems).

Fwiw, the http request was successful (200 OK), but the HTTP response told a different story. To view the answer, I added these two lines to the implementation of GTMHTTPUploadFetcher.m (possibly the best way):

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [...] NSString *dataStr = [[NSString alloc] initWithData:self.downloadedData encoding:NSUTF8StringEncoding]; NSLog(@"Downloaded data:%@",dataStr); [...] } 

JSON in dataStr:

 { "error": { "code": 403, "message": "Access Not Configured", "data": [{ "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured" }] }, "id": "gtl_1" } 
+1
source

Sorry if I make an assumption here, but I had the same error as you, and it turned out that the problem was actually my authorizer. Make sure you handle errors using auth and apply auth to service.authorizer .

 if (![self.youTubeAuth canAuthorize]) { // ... } service.authorizer = auth; 

I also had this problem due to the wrong scope for the GTMOAuth2ViewControllerTouch initializer. @"" will give you better results than the wrong scale. Check out the YouTube app example.

0
source

I think you need to enable the Drive API and Drive SDK from the API Services tab.

Turn on services to enable the project and try again.

If both options are enabled, make sure you set the argument "api_console_project_id": "xxxxxxxxxxxxx" to manifest .

0
source

I found this from here, google-youtube-api-v3-ios-app-key-403-error-code

Basically, it will work if we use Key for browser apps instead of Key for iOS apps .

0
source

I don’t know if anyone has found a solution for this, but here is what I implemented (in Swift) to avoid the application crashing:

First check the status of the Youtube channel using:

GTLQueryYouTube.queryForChannelsListWithPart with the part set to "status"

If the value of the "isLinked" parameter is not 0 in the response, then upload the video only with

GTLQueryYouTube.queryForVideosInsertWithObject

otherwise, ask the user to link the YouTube channel first.

0
source

GTLServiceYouTube * youtube = [[GTLServiceYouTube alloc] init]; youtube.APIKey = @ "- my-simple-api-access-key-"; // <- violation line youtube.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName: kKeychainItemName ClientId: kYouTubeClientID clientSecret: kYouTubeClientSecret];

-2
source

Source: https://habr.com/ru/post/952820/


All Articles