0

如何使用包含在视频标题中的关键字搜索 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:)];

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

4

1 回答 1

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;

@结尾

在 .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;
    }

我正在使用它,它对我很好!

希望对您有所帮助!

于 2012-11-24T11:19:50.197 回答