📅  最后修改于: 2023-12-03 15:05:08.174000             🧑  作者: Mango
Twitter's Search API Lab allows developers to access Twitter's real-time search functionality and retrieve tweets based on certain criteria such as keywords, hashtags, location, and language.
To get started with Twitter's Search API Lab, developers first need to create a Twitter Developer account and apply for API access. Once access is granted, developers can start to explore the API's functionality using a variety of programming languages and tools.
import requests
import json
url = "https://api.twitter.com/2/tweets/search/recent"
query = "from:twitterdev"
headers = {
"Authorization": "Bearer <API_Key>",
"User-Agent": "v2RecentSearchPython"
}
params = {
"query": query,
"expansions": "author_id",
"tweet.fields": "id,text,author_id,created_at,public_metrics",
"user.fields": "id,name,username,public_metrics",
"max_results": 100
}
response = requests.request("GET", url, headers=headers, params=params)
print(json.dumps(response.json(), indent=4, sort_keys=True))
The Search API Lab can be used for a wide range of use cases including:
Twitter's Search API Lab provides developers with a powerful and flexible tool for accessing Twitter's real-time search engine. With its wide range of filtering options, support for pagination, and comprehensive developer resources, it is a must-have tool for any developer looking to integrate Twitter search functionality into their application.