1

我正在尝试将 GData/YouTubeAPI 集成到我的项目中,但我有点卡住了。我使用了这篇文章中给出的代码:

有关在 iPhone 上使用 Google GData API - Youtube 的任何示例/教程?

我的问题是,当 GData 服务完成从互联网上抓取数据时,不会调用函数“request:finishedWithFeed:error:”。

我的程序编译并运行——并且没有出现运行时错误。我还检查了 feedURL 返回一个有效的 URL。我对此进行了调试,并且“服务”确实设法返回了一个值。

GDataServiceGoogleYouTube *service = [self youTubeService];

// feed id for user uploads
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
// construct the feed url
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:USER_NAME userFeedID:uploadsID];

// make API call

[service fetchFeedWithURL:feedURL delegate:self didFinishSelector:@selector(request:finishedWithFeed:error:)];

这是我试图让服务完成后调用的函数的标头,它与我发布的其他代码位于同一个对象中

- (void)request:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error;

解决方案 -

确保它在主线程上运行——

-(id)initWithVideosArrayURLString:(NSString*)url {
    if (self = [super init]) {
        NSLog(@"loading");
        [self performSelectorOnMainThread:@selector(initMainThreadWithURLString:)     withObject:url waitUntilDone:NO];

    }
    return self;
}

-(void)initMainThreadWithURLString:(NSString*)url {
    GDataServiceGoogleYouTube *service = [self youTubeService];

    NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
    NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"annoyingorange" userFeedID:uploadsID];
    [service fetchFeedWithURL:feedURL delegate:self   didFinishSelector:@selector(serviceTicket:finishedWithFeed:error:)];
    NSLog(@"sent");
}

- (void)serviceTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error {
        self.feed = (GDataFeedYouTubeVideo *)aFeed;

    NSLog(@"success.");
}
4

1 回答 1

2

您的代码是否在主线程上,并在启动 fetch 后返回运行循环?回调仅在应用程序的运行循环旋转时发生。

于 2010-08-14T05:23:02.087 回答