在 Objective C 上使用 YouTube API 获取元素

发布于 2024-10-18 07:56:41 字数 3885 浏览 3 评论 0原文

我已经阅读了文档,使用了示例项目,甚至检索了在我的应用程序上运行的 YouTube feed,但我无法按照我的意愿显示各个元素。

例如,我可以使用 objectAtIndex:0 获取第一个视频,但随后不知道如何获取标题、id、url 等。这是提要中我的第一个视频的 NSLog。

entry: GDataEntryYouTubeVideo 0x9eb8d50: {v:2.0 title:Evolution of Dance - By Judson Laipply contentSrc:http://www.youtube.com/v/dMH0bHeiRNg?f=standard&d=AVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDm&app=youtube_gdata etag:W/"A0cHQ347eCp7ImA9Wx9UGUo." authors:1 categories:4 links:alternate,video.responses,video.ratings,video.complaints,video.related,self id:tag:youtube.com,2008:video:dMH0bHeiRNg rating:+706815/-62385 comment:GDataComment 0x9ebeb50: {feedLink:GDataFeedLink 0x9ebf2c0: {href:http://gdata.youtube.com/feeds/api/videos/dMH0bHeiRNg/comments countHint:500786 href:http://gdata.youtube.com/feeds/api/videos/dMH0bHeiRNg/comments countHint:500786}} stats:GDataYouTubeStatistics 0x9ebfeb0: {viewCount:164922648 favoriteCount:1010039} mediaGroup:GDataYouTubeMediaGroup 0x9ec0e10: {categories:(
    "GDataMediaCategory 0x9ec41f0: {label:Comedy scheme:http://gdata.youtube.com/schemas/2007/categories.cat content:Comedy}"
) contents:(
    "GDataMediaContent 0x9ec2df0: {url:http://www.youtube.com/v/dMH0bHeiRNg?f=standard&d=AVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDm&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:360}",
    "GDataMediaContent 0x9ec3620: {url:rtsp://v5.cache7.c.youtube.com/CkcLENy73wIaPgnYRKJ3bPTBdBMYDSANFEgGUghzdGFuZGFyZHIhAVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp type:video/3gpp medium:video expression:full duration:360}",
    "GDataMediaContent 0x9ec39b0: {url:rtsp://v3.cache8.c.youtube.com/CkcLENy73wIaPgnYRKJ3bPTBdBMYESARFEgGUghzdGFuZGFyZHIhAVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp type:video/3gpp medium:video expression:full duration:360}"
) credits:(
    "GDataMediaCredit 0x9ec4730: {role:uploader scheme:urn:youtube content:judsonlaipply}"
) thumbnails:(
    "GDataMediaThumbnail 0x9ec4fb0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/default.jpg height:90 width:120 time:00:03:00 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5820: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/hqdefault.jpg height:360 width:480 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5bc0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/1.jpg height:90 width:120 time:00:01:30 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5ea0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/2.jpg height:90 width:120 time:00:03:00 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec6140: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/3.jpg height:90 width:120 time:00:04:30 unparsedAttr:yt:name}"
) keywords:GDataMediaKeywords 0x9ec66f0: {content:Dancing, comedy keywords:Dancing, comedy} description:GDataMediaDescription 0x9ec4e10: {type:plain content:For more visit http://www.mightaswelldance.com} players:(
    "GDataMediaPlayer 0x9ec2e40: {url:http://www.youtube.com/watch?v=dMH0bHeiRNg&feature=youtube_gdata_player}"
) title:GDataMediaTitle 0x9ec6aa0: {type:plain content:Evolution of Dance - By Judson Laipply} duration:360 videoID:dMH0bHeiRNg uploaded:GDataDateTime 0x7359b80: {2006-04-06T21:30:53Z}} accessControls:(
    "GDataYouTubeAccessControl 0x9ec0500: {action:comment permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0930: {action:commentVote permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec09f0: {action:videoRespond permission:moderated content:}",
    "GDataYouTubeAccessControl 0x9ebeba0: {action:rate permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ebf9f0: {action:embed permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0620: {action:list permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0b50: {action:syndicate permission:allowed content:}"
) unparsed:<gd:rating>}

I have gone through the documentation, used the sample project and even have the retrieval of a youtube feed working on my app but I am unable to get the individual elements to then displays as I desire.

I am able to get for example the first video using objectAtIndex:0 but then don't know how to get title, id, url, etc. here is an NSLog of my firs video in the feed.

entry: GDataEntryYouTubeVideo 0x9eb8d50: {v:2.0 title:Evolution of Dance - By Judson Laipply contentSrc:http://www.youtube.com/v/dMH0bHeiRNg?f=standard&d=AVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDm&app=youtube_gdata etag:W/"A0cHQ347eCp7ImA9Wx9UGUo." authors:1 categories:4 links:alternate,video.responses,video.ratings,video.complaints,video.related,self id:tag:youtube.com,2008:video:dMH0bHeiRNg rating:+706815/-62385 comment:GDataComment 0x9ebeb50: {feedLink:GDataFeedLink 0x9ebf2c0: {href:http://gdata.youtube.com/feeds/api/videos/dMH0bHeiRNg/comments countHint:500786 href:http://gdata.youtube.com/feeds/api/videos/dMH0bHeiRNg/comments countHint:500786}} stats:GDataYouTubeStatistics 0x9ebfeb0: {viewCount:164922648 favoriteCount:1010039} mediaGroup:GDataYouTubeMediaGroup 0x9ec0e10: {categories:(
    "GDataMediaCategory 0x9ec41f0: {label:Comedy scheme:http://gdata.youtube.com/schemas/2007/categories.cat content:Comedy}"
) contents:(
    "GDataMediaContent 0x9ec2df0: {url:http://www.youtube.com/v/dMH0bHeiRNg?f=standard&d=AVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDm&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:360}",
    "GDataMediaContent 0x9ec3620: {url:rtsp://v5.cache7.c.youtube.com/CkcLENy73wIaPgnYRKJ3bPTBdBMYDSANFEgGUghzdGFuZGFyZHIhAVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp type:video/3gpp medium:video expression:full duration:360}",
    "GDataMediaContent 0x9ec39b0: {url:rtsp://v3.cache8.c.youtube.com/CkcLENy73wIaPgnYRKJ3bPTBdBMYESARFEgGUghzdGFuZGFyZHIhAVEzC5trXMDfhc6PnAqxlmIO88HsQjpE1a8d1GxQnGDmDA==/0/0/0/video.3gp type:video/3gpp medium:video expression:full duration:360}"
) credits:(
    "GDataMediaCredit 0x9ec4730: {role:uploader scheme:urn:youtube content:judsonlaipply}"
) thumbnails:(
    "GDataMediaThumbnail 0x9ec4fb0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/default.jpg height:90 width:120 time:00:03:00 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5820: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/hqdefault.jpg height:360 width:480 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5bc0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/1.jpg height:90 width:120 time:00:01:30 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec5ea0: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/2.jpg height:90 width:120 time:00:03:00 unparsedAttr:yt:name}",
    "GDataMediaThumbnail 0x9ec6140: {url:http://i.ytimg.com/vi/dMH0bHeiRNg/3.jpg height:90 width:120 time:00:04:30 unparsedAttr:yt:name}"
) keywords:GDataMediaKeywords 0x9ec66f0: {content:Dancing, comedy keywords:Dancing, comedy} description:GDataMediaDescription 0x9ec4e10: {type:plain content:For more visit http://www.mightaswelldance.com} players:(
    "GDataMediaPlayer 0x9ec2e40: {url:http://www.youtube.com/watch?v=dMH0bHeiRNg&feature=youtube_gdata_player}"
) title:GDataMediaTitle 0x9ec6aa0: {type:plain content:Evolution of Dance - By Judson Laipply} duration:360 videoID:dMH0bHeiRNg uploaded:GDataDateTime 0x7359b80: {2006-04-06T21:30:53Z}} accessControls:(
    "GDataYouTubeAccessControl 0x9ec0500: {action:comment permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0930: {action:commentVote permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec09f0: {action:videoRespond permission:moderated content:}",
    "GDataYouTubeAccessControl 0x9ebeba0: {action:rate permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ebf9f0: {action:embed permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0620: {action:list permission:allowed content:}",
    "GDataYouTubeAccessControl 0x9ec0b50: {action:syndicate permission:allowed content:}"
) unparsed:<gd:rating>}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2024-10-25 07:56:41

已解决,将调用与上面的 xml 进行比较,以便您可以在其他 gdata feed 上使用

GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
        NSString *title = [[entry title] stringValue];
        NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];

        cell.textLabel.text = title;

        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
        cell.imageView.image = [UIImage imageWithData:data];

resolved, compare the calls with the xml above so that you may use on other gdata feeds

GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
        NSString *title = [[entry title] stringValue];
        NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];

        cell.textLabel.text = title;

        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
        cell.imageView.image = [UIImage imageWithData:data];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文