Search code examples
iphoneobjective-cyoutube-apikeywordgdata-api

How search Youtube videos by keywords in objective-c


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?


Solution

  • 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!