Giphy Random
Get random GIF from Giphy.
Installation
$ npm install giphy-random
If you want to use this library directly on the browser, you have to manually include the axios library too:
Usage
const giphyRandom = ; async { const API_KEY = "YOUR API KEY"; const data = await ; console;};
The data
will contain a GIF Object.
To get your Giphy API key, sign up here: developers.giphy.com/dashboard.
Recipes
Filter by Tag
const giphyRandom = ; async { const API_KEY = "YOUR API KEY"; const data = await ; console;};
Override the Default Rating
By default, Giphy will use the G
—general audience—rating. To override this, pass the rating
argument:
const giphyRandom = ; async { const API_KEY = "YOUR API KEY"; const data = await ; console;};
API
giphyRandom()
Parameters
apiKey
(String
): Your Giphy API key.tag
(optionalString
): The tag to filter the result.rating
(optionalString
): MPAA-style rating to filter the result, default tog
.
Here's the rating
value that you can pass:
You can pass the following value as rating
:
y
: Appropriate for all childreng
: General audiences (default)pg
: Parental guidance suggestedpg-13
: Parents strongly cautionedr
: Restricted
Return
It returns a Promise
which when resolved contains a Giphy API response object. Here's an example of the resolved value with some properties that you might be interested in:
data: type: "gif" id: "H2fORSKZw4SCQ" slug: "cats-cat-gifs-kitten-H2fORSKZw4SCQ" url: "https://giphy.com/gifs/cats-cat-gifs-kitten-H2fORSKZw4SCQ" embed_url: "https://giphy.com/embed/H2fORSKZw4SCQ" source_post_url: "https://kittehkats.tumblr.com/post/101035478921/found-on-lh3-googleusercontent-com" images: downsized: url: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy-downsized.gif" width: "210" height: "138" size: "1930051" original: url: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy.gif" width: "210" height: "138" size: "1930051" frames: "165" mp4: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy.mp4" mp4_size: "781811" webp: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy.webp" webp_size: "1368374" // Omitted... title: "cat kitten GIF" image_url: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy.gif" image_mp4_url: "https://media1.giphy.com/media/H2fORSKZw4SCQ/giphy.mp4" image_width: "210" image_height: "138" caption: "" // Omitted... meta: status: 200 msg: "OK" response_id: "5be8329e796b703936aff12b"
Note that there are many properties omitted from the example above. Check Giphy documentation for more detail.
License
Legal
This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Giphy or any of its affiliates or subsidiaries. This is an independent and unofficial API.