Fetch, Search GIF more easily and customised manner from Tenor
This library is MIT licensed, which means you can use it anywhere without any consent from justkawal.
Add this to your package's pubspec.yaml
file:
dependencies:
tenor: ^2.0.0
You can install packages from the command line:
with pub
:
$ pub get
with Flutter
:
$ flutter packages get
Now in your Dart
code, you can use:
import 'package:tenor/tenor.dart';
Initialize Tenor library
Tenor tenor = Tenor(apiKey: 'ApiKey', language: TenorLanguage.English);
TenorLanguage provides codes for different ISO 639-1 language code
var englishCode = TenorLanguage.English;
Requests anon_id
from tenor
Get an anonymous ID for a new user.
Store the ID in the client’s cache for use on any additional API calls made by the user, either in this session or any future sessions.
Note: using anonymous ID to personalize API responses requires custom development.
For more info on anon_id: https://tenor.com/gifapi/documentation#endpoints-anonymousid
var tenorApi = Tenor(apiKey: 'Tenor Api');
String? res = await tenorApi.generateAnonId();
Returns response containing a list of the current global trending GIFs. The trending stream is updated regularly throughout the day.
Important: limit
: 1 <= limit <= 50
// Future<TenorResponse?> requestTrendingGIF({
// int limit = 20,
// ContentFilter contentFilter = ContentFilter.high,
// GifSize size = GifSize.all,
// MediaFilter mediaFilter = MediaFilter.minimal,
// String anon_id = '',
// bool canRegisterShare = false,
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// fetch trending Gif
TenorResponse? res = await tenor.requestTrendingGIF(limit: 5);
res?.results.forEach((TenorResult tenorResult) {
var title = tenorResult.title;
var media = tenorResult.media;
print('$title: gif : ${media?.gif?.previewUrl?.toString()}');
});
Returns response containing a list of the searched Gif from Tenor.
Important: limit
: 1 <= limit <= 50
// Future<TenorResponse?> searchGIF(
// String search, {
// int limit = 20,
// ContentFilter contentFilter = ContentFilter.high,
// GifSize size = GifSize.all,
// MediaFilter mediaFilter = MediaFilter.minimal,
// String anon_id = '',
// bool canRegisterShare = false,
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// search Gif
TenorResponse? res = await tenor.searchGIF('universe', limit: 5);
res?.results.forEach((TenorResult tenorResult) {
var title = tenorResult.title;
var media = tenorResult.media;
print('$title: gif : ${media?.gif?.previewUrl?.toString()}');
});
Get a randomized list of GIFs for a given search term. This differs from the search function which returns a rank ordered list of GIFs for a given search term.
Important: limit
: 1 <= limit <= 50
// Future<TenorResponse?> randomGIF(
// String search, {
// int limit = 20,
// ContentFilter contentFilter = ContentFilter.high,
// GifSize size = GifSize.all,
// MediaFilter mediaFilter = MediaFilter.minimal,
// String anon_id = '',
// bool canRegisterShare = false,
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// random Gif
TenorResponse? res = await tenor.randomGIF('universe', limit: 5);
res?.results.forEach((TenorResult tenorResult) {
var title = tenorResult.title;
var media = tenorResult.media;
print('$title: gif : ${media?.gif?.previewUrl?.toString()}');
});
Search suggestions helps a user narrow their search or discover related search terms to find a more precise GIF. Results are returned in order of what is most likely to drive a share for a given term, based on historic user search and share behavior.
Important: limit
: 1 <= limit <= 50
// Future<List<String>> searchSuggestions(
// String search, {
// int limit = 20,
// bool automaticallyRegisterShare = false,
// String anon_id = '',
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// suggestions
List<String> suggestions = await tenor.searchSuggestions('universe', limit: 5);
Returns response containing a list of the current trending search terms. The list is updated Hourly by Tenor’s AI.
Important: limit
: 1 <= limit <= 50
// Future<List<String>> trendingSearch(
// int limit = 20,
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// trending search results
List<String> suggestions = await tenor.trendingSearch(limit: 5);
Returns response containing a list of completed search terms given a partial search term. The list is sorted by Tenor’s AI
and the number of results will decrease as Tenor’s AI
becomes more certain.
Important: limit
: 1 <= limit <= 50
// Future<List<String>> autoComplete(
// String search, {
// int limit = 20,
// bool automaticallyRegisterShare = false,
// String anon_id = '',
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// auto complete results
List<String> autoCompleted = await tenor.autoComplete('un', limit: 5);
This helps further tune Tenor’s Search Engine AI, helping users more easily find the perfect GIF.
As Tenor’s service evolves, it will be used to better tune search results to your users’ specific languages, cultures, and social trends.
Note: To use registerShare
It is important pass the anon_id
and language_key
on the tenor api initialization.
For more info head to: https://tenor.com/gifapi/documentation#endpoints-registershare
String userId = 'Anon_id generated from Tenor Server';
Tenor tenor = Tenor(apiKey: 'ApiKey', language: TenorLanguage.English);
TenorResult tenorResultObject = ............;
String? isRegistered = await tenorResultObject.registerShare();
if (isRegistered != null && isRegistered == 'ok'){
print('Sharing Registered: $isRegistered');
} else {
print('not registered ');
}
Requests Categories
from tenor
// Future<List<TenorCategories?>> requestCategories({
// ContentFilter contentFilter = ContentFilter.high,
// CategoryType categoryType = CategoryType.featured,
// })
Tenor tenor = Tenor(apiKey: 'Tenor Api');
// list of categories
List<TenorCategories?> categories = await tenor.requestCategories();
key | description |
---|---|
limit | eg. limit the number of GIF to be fetched. limit can vary from 1 to 50 |
contentFilter | (values: off , low , medium , high ) specify the content safety filter level. eg. contentFilter: ContentFilter.low |
mediaFilter | (values: basic , minimal ) Reduce the Number of GIF formats returned in response. minimal- (tinygif, gif, and mp4) . basic- (nanomp4, tinygif, tinymp4, gif, mp4, and nanogif) eg. mediaFilter: MediaFilter.minimal |
size | GIFs with aspect ratios that fit with in the selected range. values: (all , wide , standard ), all - no constraints, wide - 0.42 <= aspect ratio <= 2.36, standard - .56 <= aspect ratio <= 1.78 |
fetchNext()
is used to get next set of response for the current query
// Future<TenorResponse?> fetchNext({int limit = 20});
// here the fetchNext function is used to call next set of GIF which is sequenced after current response
TenorResponse? firstSetResponse = await tenor. /*.... Functions used to get TenorResponse? ....*/
TenorResponse? nextResult = await firstSetResponse?.fetchNext();
nextResult?.results.forEach((tenorResult) {
var title = tenorResult.title;
var media = tenorResult.media;
print('$title: gif : ${media?.gif?.previewUrl?.toString()}');
});
key | description |
---|---|
limit | eg. limit the number of GIF to be fetched. limit can vary from 1 to 50 |
- Your donation would help me to pay my college fees @ [ Fleming College, Canada ].
- Mac
- Paypal: https://paypal.me/kawal7415
- We are thinking what we should give next after giving all these features.
- If you have any new feature request then go ahead and ping me, I'll integrate it.