Python / Twitter API v2 / Stream (see description)
Back to Collection Items
import sys
import chilkat
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = chilkat.CkHttp()
# Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>")
sbResponseBody = chilkat.CkStringBuilder()
success = http.QuickGetSb("https://api.twitter.com/2/tweets/search/stream",sbResponseBody)
if (success == False):
print(http.lastErrorText())
sys.exit()
print("Response status code = " + str(http.get_LastStatus()))
print(sbResponseBody.getAsString())
Curl Command
curl -X GET
-H "Authorization: Bearer <access_token>"
https://api.twitter.com/2/tweets/search/stream
Postman Collection Item JSON
{
"name": "Stream (see description)",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.twitter.com/2/tweets/search/stream",
"protocol": "https",
"host": [
"api",
"twitter",
"com"
],
"path": [
"2",
"tweets",
"search",
"stream"
],
"query": [
{
"key": "tweet.fields",
"value": "",
"description": "Comma-separated list of fields for the Tweet object.\n\nAllowed values:\nattachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,public_metrics,referenced_tweets,reply_settings,source,text,withheld\n\nDefault values:\nid,text",
"disabled": true
},
{
"key": "expansions",
"value": "",
"description": "Comma-separated list of fields to expand. Expansions enable requests to expand an ID into a full object in the includes response object.\n\nAllowed values: attachments.poll_ids,attachments.media_keys,author_id,geo.place_id,in_reply_to_user_id,referenced_tweets.id,entities.mentions.username,referenced_tweets.id.author_id\n\nDefault values: none",
"disabled": true
},
{
"key": "media.fields",
"value": "",
"description": "Comma-separated list of fields for the media object. Expansion required.\n\nAllowed values:\nduration_ms,height,media_key,preview_image_url,public_metrics,type,url,width\n\nDefault values:\nmedia_key,type",
"disabled": true
},
{
"key": "poll.fields",
"value": "",
"description": "Comma-separated list of fields for the poll object. Expansion required.\n\nAllowed values:\nduration_minutes,end_datetime,id,options,voting_status\n\nDefault values:\nid,options",
"disabled": true
},
{
"key": "place.fields",
"value": "",
"description": "Comma-separated list of fields for the place object. Expansion required.\n\nAllowed values:\ncontained_within,country,country_code,full_name,geo,id,name,place_type\n\nDefault values:\nid,full_name",
"disabled": true
},
{
"key": "user.fields",
"value": "",
"description": "Comma-separated list of fields for the user object. Expansion required.\n\nAllowed values:\ncreated_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld\n\nDefault values:\nid,name,username",
"disabled": true
},
{
"key": "backfill_minutes",
"value": null,
"description": "Provide a whole number between 1 and 5. \n\nThis parameter enables the recovery of up to five minutes worth of data that may have been missed during a disconnection. \n\nThe backfilled Tweets will automatically flow through a reconnected stream, with older Tweets generally being delivered before any newly matching Tweets.\nThis feature will deliver all Tweets that matched your rules and were published during the timeframe selected, meaning that if you were disconnected for 90 seconds, and you requested two minutes of backfill, you will receive 30 seconds worth of duplicate Tweets. Due to this, you should make sure your system is tolerant of duplicate \ndata.\n\n*This feature is currently only available to the academic research product track*.",
"disabled": true
}
]
},
"description": "Streams Tweets in real-time based on a specific set of filter rules.\n\nPlease note streaming responses are currently [not supported](https://github.com/postmanlabs/postman-app-support/issues/5040) in Postman. Use this to help form your request, then click on Code > cURL. Copy the cURL command and paste in terminal to view the response.\n\n[Sign up](https://t.co/signup) for the Twitter API"
},
"response": [
{
"name": "429 - Too Many Requests",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.twitter.com/2/tweets/search/stream",
"protocol": "https",
"host": [
"api",
"twitter",
"com"
],
"path": [
"2",
"tweets",
"search",
"stream"
],
"query": [
{
"key": "tweet.fields",
"value": "",
"description": "attachments,author_id,context_annotations,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,public_metrics,referenced_tweets,source,text,withheld",
"disabled": true
},
{
"key": "expansions",
"value": null,
"description": "Comma-separated list of fields to expand. Expansions enable requests to expand an ID into a full object in the includes response object.\nAllowed values: attachments.poll_ids,attachments.media_keys,author_id,geo.place_id,in_reply_to_user_id,referenced_tweets.id\nDefault values: none",
"disabled": true
},
{
"key": "media.fields",
"value": null,
"description": "duration_ms,height,media_key,non_public_metrics,organic_metrics,preview_image_url,promoted_metrics,public_metrics,type,url,width",
"disabled": true
},
{
"key": "poll.fields",
"value": null,
"description": "duration_minutes,end_datetime,id,options,voting_status",
"disabled": true
},
{
"key": "place.fields",
"value": null,
"description": "contained_within,country,country_code,full_name,geo,id,name,place_type",
"disabled": true
},
{
"key": "user.fields",
"value": null,
"description": "created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,withheld",
"disabled": true
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "cache-control",
"value": "no-cache, no-store, max-age=0"
},
{
"key": "content-disposition",
"value": "attachment; filename=json.json"
},
{
"key": "content-encoding",
"value": "gzip"
},
{
"key": "content-length",
"value": "171"
},
{
"key": "content-type",
"value": "application/json; charset=utf-8"
},
{
"key": "date",
"value": "Thu, 09 Jul 2020 15:57:37 GMT"
},
{
"key": "server",
"value": "tsa_b"
},
{
"key": "strict-transport-security",
"value": "max-age=631138519"
},
{
"key": "x-access-level",
"value": "read"
},
{
"key": "x-connection-hash",
"value": "d97d000f91428f529ecc41379e86b1c9"
},
{
"key": "x-content-type-options",
"value": "nosniff"
},
{
"key": "x-frame-options",
"value": "SAMEORIGIN"
},
{
"key": "x-rate-limit-limit",
"value": "50"
},
{
"key": "x-rate-limit-remaining",
"value": "47"
},
{
"key": "x-rate-limit-reset",
"value": "1594310686"
},
{
"key": "x-response-time",
"value": "291"
},
{
"key": "x-xss-protection",
"value": "0"
}
],
"cookie": [
],
"body": "{\n \"title\": \"ConnectionException\",\n \"detail\": \"This stream is currently at the maximum allowed connection limit.\",\n \"connection_issue\": \"TooManyConnections\",\n \"type\": \"https://api.twitter.com/2/problems/streaming-connection\"\n}"
}
]
}