0

how can i search youtube videos using keyword contained into video's title? I use objective-c youtube API. In my example, I use this code to search youtube videos by author-user

NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"myAuthor"userFeedID:uploadsID];

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

Where can I found some pratical example and all documentation about it?

Safari
  • 11,437
  • 24
  • 91
  • 191

1 Answers1

1

you can use the following code to get all searched videos in TableView

in .h file

#import <UIKit/UIKit.h>
#import "GData.h"
#import "GDataFeedYouTubeVideo.h"

@interface RootViewController : UIViewController {

    GDataFeedYouTubeVideo* feed;
    NSMutableDictionary *imageDownloadsInProgress; 
}


 @property(retain,nonatomic) NSMutableDictionary *imageDownloadsInProgress;
 @property(retain,nonatomic)GDataFeedYouTubeVideo* feed;

 -(void)requestFinishForYouTube:(GDataServiceTicket *)ticket FinishedWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error;


- (void)setFlickrPhotoONU:(NSString*)flickrPhoto:(UIImageView *)imgV;
-(void)downloadImagesInBackGroundONU:(NSDictionary*)data;

@end

in .m file

 @interface RootViewController (PrivateMethods)

     -(GDataServiceGoogleYouTube *)youTubeService;

 @end


 @implementation RootViewController

  @synthesize feed,imageDownloadsInProgress;

-(GDataServiceGoogleYouTube *)youTubeService
{
    static GDataServiceGoogleYouTube *_service = nil;
     if (!_service)
    {
         _service = [[GDataServiceGoogleYouTube alloc]init];
         [_service setUserAgent:@"AppWhirl-Userapp-1.0"];
         [_service setShouldCacheDatedData:YES];
         [_service setServiceShouldFollowNextLinks:YES];
    }
     [_service setUserCredentialsWithUsername:nil password:nil];

    return _service;
}

   - (void)viewDidLoad
   {

       GDataServiceGoogleYouTube *service = [self youTubeService];

      NSString *searchString = @"Leo Messi Goal!"; // You can write here whatever you want to looking for !!


       NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForFeedID:nil];

        GDataQueryYouTube* query = [GDataQueryYouTube  youTubeQueryWithFeedURL:feedURL];

       [query setVideoQuery:searchString];

       [query setMaxResults:50];

        [service fetchFeedWithQuery:query delegate:self didFinishSelector:@selector(requestFinishForYouTube:FinishedWithFeed:error:)];

       [super viewDidLoad];
  }


      -(void)requestFinishForYouTube:(GDataServiceTicket *)ticket FinishedWithFeed:(GDataFeedBase *)aFeed error:(NSError *)error 
    {
          finish = 1;
          NSLog(@"%@",aFeed);
          self.feed = (GDataFeedYouTubeVideo *)aFeed;
    }

I am using it and it working to fine with me!

Hope it will help you!

iDhaval
  • 7,824
  • 2
  • 21
  • 30
  • i tried it but i have a crash.. i think that this is wrong: GDataQueryYouTube* query = [GDataQueryYouTube youTubeQueryWithFeedURL:nil]; is ok the nil parameter? – Safari Nov 24 '12 at 13:11
  • This is the solution: http://stackoverflow.com/questions/3507967/youtube-uitableview-from-a-search-query-using-gdata – Safari Nov 24 '12 at 17:44