作者:传闻中的张先生 | 来源:互联网 | 2023-09-16 19:28
类型:“渠道”
仅对于视频,请指定>类型:“视频”
仅对播放列表指定>类型:“播放列表”
maxResults(int)可以是1-50'
var dateTimeString = "20181230183000000";
DateTimeOffset dto;
if (DateTimeOffset.TryParseExact(dateTimeString,"yyyyMMddHHmmssfff",CultureInfo.invariantculture,DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal,out dto))
{
Console.WriteLine(dto);
}
此代码获取json数据以存储在ytResult中:
int max = 25;
String type = "channel";
YoutubeAPI ytApi = new YoutubeAPI(key,maxResults: max,Type: type);
这是我的全部代码,但未得到任何响应
这是我的颤动代码,用于按关键字列出视频
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:youtube_api/youtube_api.dart';
import 'package:timeago/timeago.dart' as timeago;
import '../../generated/l10n.dart';
import './video.dart';
class VideosPage extends StatefulWidget {
@override
_VideosPageState createState() => _VideosPageState();
}
class _VideosPageState extends State
with AutomaticKeepAliveClientMixin {
static String key = "AIzaSy...__xxxxxxxx_**********";
bool recordsLoaded = false;
static int maxResults = 25;
// static String videosType = "channel";
static String videosType = "videos";
// static String videosType = "playlist";
YoutubeAPI ytApi = new YoutubeAPI(
key,maxResults: maxResults,type: videosType,);
List ytResult = [];
callAPI() async {
// print('UI callled');
// CircularProgressIndicator();
String query = "FLUTTER";
ytResult = await ytApi.search(query);
setState(() {
// print('UI Updated 2');
recordsLoaded = true;
});
}
@override
void initState() {
// _loadList();
// super.initState();
super.initState();
callAPI();
// print('hello');
recordsLoaded = false;
}
@override
Widget build(BuildContext context) {
super.build(context);
// var locale = Localizations.localeOf(context).languageCode;
timeago.setLocaleMessages('fr',timeago.FrMessages());
timeago.setLocaleMessages('en',timeago.EnMessages());
return Scaffold(
appBar: AppBar(
title: Text(S.of(context).titleVideos),elevation: 0,),body: Container(
child: recordsLoaded
? ListView.builder(
itemCount: ytResult.length,itemBuilder: (_,int index) => listItem(index))
: Center(
child: Container(
child: CircularProgressIndicator(),)),);
}
Widget listItem(index) {
var publishedAt =
timeago.format(DateTime.parse(ytResult[index].publishedAt));
return new Card(
child: new Container(
margin: EdgeInsets.symmetric(vertical: 7.0),padding: EdgeInsets.all(6.0),child: new Row(
children: [
new InkWell(
child: new CachedNetworkImage(
imageUrl: ytResult[index].thumbnail['default']['url'],width: 90,height: 90,onTap: () {
print(ytResult[index].url);
Navigator.push(
context,MaterialPageRoute(
builder: (context) => YouTubeVideoPlayer(
title: ytResult[index].title,url: ytResult[index].id),);
},new Padding(padding: EdgeInsets.only(right: 10.0)),new Expanded(
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,crossAxisAlignment: CrossAxisAlignment.start,children: [
new InkWell(
child: new Text(
ytResult[index].title,softWrap: true,style: TextStyle(fontSize: 16.0),onTap: () {
Navigator.push(
context,MaterialPageRoute(
builder: (context) => YouTubeVideoPlayer(
title: ytResult[index].title,);
},new Padding(padding: EdgeInsets.only(bottom: 1.5)),new Text(
ytResult[index].channelTitle,style: TextStyle(fontSize: 14.0,color: Colors.grey[600]),new Padding(padding: EdgeInsets.only(bottom: 3.0)),new Text(
publishedAt,style: TextStyle(fontSize: 12.0,color: Colors.grey),]))
],);
}
}