A simple and easy-to-use wrapper for the Tenor API, enabling quick and effective integrations.
npm install tenor-gif-apitenor-gif-api is a simple and easy-to-use wrapper for the Tenor API, enabling quick and effective integrations for searching and sharing GIFs and stickers. This package simplifies the process of interacting with Tenor's extensive multimedia library.
bash
npm install tenor-gif-api
`
Usage
Basic Example
Here's a quick example of how to use tenor.js to search for GIFs:
`typescript
import { TenorClient } from 'tenor.js';
const client = new TenorClient('YOUR_API_KEY');
async function searchGIFs() {
const response = await client.search.query({ q: 'funny', limit: 5 });
console.log(response.results);
}
searchGIFs();
`
Services
$3
Search for GIFs, stickers, and other media.
`typescript
Copiar código
const response = await client.search.getGIFs({ q: 'hello', limit: 10 });
`
$3
Get a list of the current global featured GIFs.
`typescript
const response = await client.featured.getFeatured({ limit: 5 });
`
$3
Retrieve a list of GIF categories.
`typescript
const response = await client.categories.getCategories();
`
$3
Get a list of alternative search terms for a given search term.
`typescript
const response = await client.suggestions.getSuggestions({ q: 'happy' });
`
$3
Fetch a list of completed search terms for a given partial search term.
`typescript
const response = await client.autocomplete.getAutocomplete({ q: 'fun' });
`
$3
Fetch a list of the current trending search terms.
`typescript
const response = await client.trending.getTrendingTerms();
`
$3
Register a user's sharing of a GIF or sticker.
`typescript
await client.registerShare.registerShare({ id: 'GIF_ID' });
`
$3
Fetch GIFs, stickers, or a combination of both for the specified IDs.
`typescript
const response = await client.posts.getPosts({ ids: 'GIF_ID' });
`
API Reference
$3
The TenorClient class provides access to all services available through the Tenor API.
#### Constructor
`typescript
constructor(apiKey: string, clientKey?: string)
`
- apiKey: Your Tenor API key.
- clientKey: Optional. A unique client key to differentiate integrations.
#### Services Overview
- search: Handles searching for GIFs, stickers, and other content.
- featured: Retrieves featured content.
- categories: Fetches available categories.
- suggestions: Provides search suggestions.
- autocomplete: Autocompletes search terms.
- trending: Gets trending search terms.
- registerShare: Registers user shares.
- posts: Fetches posts by ID.
For detailed parameters and examples for each service, refer to the API documentation.
Configuration
To use tenor.js, you need to configure your API key. Optionally, you can provide a clientKey to differentiate your integrations.
Setting the API Key
You can set the API key when initializing TenorClient:
`typescript
const client = new TenorClient('YOUR_API_KEY');
`
- Optional Configuration
- clientKey: A unique string to differentiate multiple integrations.
Error Handling
All methods return promises that may reject with errors. Use try...catch blocks or .catch() methods to handle errors.
`typescript
try {
const response = await client.search.getGIFs({ q: 'oops' });
} catch (error) {
console.error('Error fetching GIFs:', error);
}
``