我正在尝试将GData / YouTubeAPI集成到我的项目中,但我有点卡住了。我使用了这篇文章中给出的代码:
Any examples/tutorials on using Google GData API - Youtube on iphone?
我的问题是当GData服务完成从网站抓取数据时,不会调用函数'request:finishedWithFeed:error:'。
我的程序编译并运行 - 并且没有运行时错误。我也检查过,feedURL返回一个有效的URL。我调试了这个,'service'确实设法返回一个值。
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.");
}
答案 0 :(得分:2)
您的代码是否在主线程上,并在启动提取后返回到运行循环?仅当应用程序的运行循环正在旋转时才会发生回调。