当没有互联网连接时,谷歌目标c api:completionHandler从不调用



iOS初学者,我正在尝试使用谷歌目标c api在youtube上上传视频。在大多数情况下,它只是起作用。视频可以上传,如果出现错误,我的回调会收到错误。

但是,如果我关闭设备上的互联网连接,则永远不会调用回调。(即使它被称为其他类型的错误,如不正确的标题或不正确的标签)

我个人的猜测是,虽然我为GTLServiceYouTube设置了回调,但我没有明确为GTMOAuth2Authentication设置回调,因此没有调用。但我不知道该如何设置,在任何地方都找不到。

请注意,在我的情况下,我确实需要我的用户能够上传视频,而无需输入他们的凭据,因此需要手动初始化GTMOAuth2Authentication。

这是我的代码,如果我做错了什么,请告诉我如何修复。

    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.");
                                                  }];

我已经追踪到GTMHTTP蚀刻机969 的电话缺失

  @synchronized(self) {
    target = [[delegate_ retain] autorelease];
    sel = finishedSel_;
#if NS_BLOCKS_AVAILABLE
    block = [[completionBlock_ retain] autorelease];
#endif
  }

同步块被调用两次,一次调用GTMOAuth2Authentication回调,第二次调用。。。好无

最近在库中修复了上传重试处理中的一个错误。尝试更新您的Google API库资源。

相关内容

  • 没有找到相关文章