如何在objective-c中按关键字搜索Youtube视频

时间:2012-11-24 10:52:22

标签: iphone objective-c youtube-api keyword gdata-api

如何使用视频标题中包含的关键字搜索YouTube视频?我使用objective-c youtube API。 在我的示例中,我使用此代码按作者用户

搜索youtube视频
NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"myAuthor"userFeedID:uploadsID];

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

我在哪里可以找到一些实用的例子和所有关于它的文档?

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码获取TableView中所有搜索过的视频

.h文件中的

#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

.m文件中的

 @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;
    }

我正在使用它,它与我合作!

希望它会对你有所帮助!