/
main.dart
63 lines (51 loc) · 1.77 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:tenor/src/utility/language_codes.dart';
import 'package:tenor/tenor.dart';
import 'dart:io';
int i = 0;
void main() async {
// replce 'ApiKey' with your own key -> 'You Own Api Key'
var apiKey = File('/path to api key/apiKey').readAsStringSync();
var api = Tenor(apiKey: '$apiKey', language: TenorLanguage.English);
///
/// exmaple of searching of keyword on tenor
///
var anon_id = await api.generateAnonId();
print(' Fetching 5 donate searched Gif ');
var res = await api.searchGIF('donate', limit: 5);
printTenorResponse(res);
log(' Fetching Next 5 Results ');
printTenorResponse(await res?.fetchNext(limit: 5));
///
/// exmaple of requesting trending Gif
///
log('Fetching 5 Trending Gif');
res = await api.requestTrendingGIF(limit: 5, anon_id: anon_id ?? '');
if (res?.results.isNotEmpty ?? false) {
var val = await res?.results.first.registerShare();
print(val.toString());
}
//printTenorResponse(res);
/// next results
log('Fetching Next 5 Resultsf');
printTenorResponse(await res?.fetchNext(limit: 5));
///
/// exmaple of requesting categories
///
log(' Fetching Categories ');
var categories = await api.requestCategories();
print(categories.join('\n').toString());
///
/// exmaple of requesting auto complete list of possible words based on search parameter
///
log(' Fetching Auto Complete Suggestions ');
var suggestions = await api.autoComplete('doc');
print(suggestions.toString());
}
void printTenorResponse(TenorResponse? res) {
res?.results.forEach((tenorResult) {
var title = tenorResult.title;
var media = tenorResult.media;
print('$title: gif ${i++} : ${media?.gif?.previewUrl?.toString()}');
});
}
void log(String s) => print('\n\n--------- $s ------------\n\n');