Hey Guys,
I'm trying to integrate GData/YouTubeAPI into my project but I'm a bit stuck. I used the code that was given in this post:
My problem is that the function 'request:finishedWithFeed:error:' is not called when the GData service is done grabbing data off the interwebs.
My program compiles and runs – and no runtime errors present themselves. I also checked and feedURL returns a valid URL. I debugged this and 'service' does manage to return a value.
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:)];
This is the header for the function I'm trying to get service to call when its done, it's located in the same object as the other code i've posted
- (void)request:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error;
SOLUTION --
make sure its running on main thread --
-(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.");
}