iOS beginner, I am trying to upload videos on youtube using the google objective c api. In most cases, it just works. Videos can be uploaded and my callback receives errors if they occur.
But if I turn off the internet connection on the device, the callback is never called. (even though it is called for other types of errors, like incorrect title or incorrect tags)
My personal guess it that while I have set a callback for GTLServiceYouTube, I haven't explicitly set one for GTMOAuth2Authentication, hence the absence of a call. But I am not sure how to set one and found nothing about it anywhere.
Note that in my situation, I really need my users to be able to upload a video without having to enter their credentials, hence the manual initialization of the GTMOAuth2Authentication.
Here is my code, please tell me if I am doing something wrong and how I could fix it.
NSString *clientID = @"185815387242-hqo2d4e06j4hk4f02t5gvn7jcifakdvr.apps.googleusercontent.com";
NSString *clientSecret = @"2LKi7orHyphJXXXXXXXXXXXX";
NSURL *tokenURL = [NSURL URLWithString:@"https://accounts.google.com/o/oauth2/token"];
NSString *redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:kGTMOAuth2ServiceProviderGoogle
tokenURL:tokenURL
redirectURI:redirectURI
clientID:clientID
clientSecret:clientSecret];
[auth setKeysForResponseString:@"email=annonce-video-i-6620%40pages.plusgoogle.com&isVerified=1&refresh_token=1%2FFFo5rlNs51u9g2TpCIE2oji_ACvDPc0XXXXXXXXXXXX&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&serviceProvider=Google&userID=107586507912247324352"];
//////////////////////////////////////////////////
GTLServiceYouTube *youTubeService = [[GTLServiceYouTube alloc] init];
// Have the service object set tickets to fetch consecutive pages
// of the feed so we do not need to manually fetch them.
youTubeService.shouldFetchNextPages = YES;
// Have the service object set tickets to retry temporary error conditions
// automatically.
youTubeService.retryEnabled = YES;
youTubeService.authorizer = auth;
// Status.
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
// Snippet.
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = @"TITLE";
NSString *desc = @"DESC";
if ([desc length] > 0) {
snippet.descriptionProperty = desc;
}
NSString *tagsStr = @"TAGS";
if ([tagsStr length] > 0) {
snippet.tags = [tagsStr componentsSeparatedByString:@","];
}
GTLYouTubeVideo *video = [GTLYouTubeVideo object];
video.status = status;
video.snippet = snippet;
// Get a file handle for the upload data.
NSString *path = @"AVALIDPATH";
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
if (fileHandle) {
NSString *mimeType = @"video/mp4";
GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithFileHandle:fileHandle
MIMEType:mimeType];
uploadParameters.uploadLocationURL = nil;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video
part:@"snippet,status"
uploadParameters:uploadParameters];
GTLServiceYouTube *service = youTubeService;
[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeVideo *uploadedVideo,
NSError *error) {
//NEVER CALLED WHEN THE DEVICE IS IN AIRPLANE MODE
NSLog(@"And call me maybe.");
}];
I have traced back the absence of call to GTMHTTPFetcher line 969
@synchronized(self) {
target = [[delegate_ retain] autorelease];
sel = finishedSel_;
#if NS_BLOCKS_AVAILABLE
block = [[completionBlock_ retain] autorelease];
#endif
}
The synchronized block is called twice, once to call the GTMOAuth2Authentication callback, and a second time to call... Well... nil
A bug in retry handling on uploads was recently fixed in the library. Try updating your Google API library sources.