-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathgiphy_search.py
More file actions
24 lines (19 loc) · 909 Bytes
/
giphy_search.py
File metadata and controls
24 lines (19 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests
# REPLACE the following with the API key you generated.
API_KEY = "REPLACE_DEMO_API_KEY"
endpoint = "https://api.giphy.com/v1/gifs/search"
# Define the search term you want to use.
search_term = "shrug"
# In the query parameters you can define:
# 1. The number of GIFs to return using the `limit` parameter.
# 2. The query term to search for using the `q` parameter.
# 3. The accepted rating of the GIFs returned using the `rating` parameter
# https://developers.giphy.com/docs/optional-settings#rating
params = {"api_key": API_KEY, "limit": 3, "q": search_term, "rating": "g"}
# The response will contain a list with all the GIFs that match your query.
# For each of those, you want to get the `title` and `url` fields.
response = requests.get(endpoint, params=params).json()
for gif in response["data"]:
title = gif["title"]
url = gif["url"]
print("%s | %s" % (title, url))