Chilkat Online Tools

Node.js / Twitter API v2 / Stream (see description)

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>";

    var sbResponseBody = new chilkat.StringBuilder();
    success = http.QuickGetSb("https://api.twitter.com/2/tweets/sample/stream",sbResponseBody);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log("Response status code = " + http.LastStatus);
    console.log(sbResponseBody.GetAsString());

}

chilkatExample();

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://api.twitter.com/2/tweets/sample/stream

Postman Collection Item JSON

{
  "name": "Stream (see description)",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.twitter.com/2/tweets/sample/stream",
      "protocol": "https",
      "host": [
        "api",
        "twitter",
        "com"
      ],
      "path": [
        "2",
        "tweets",
        "sample",
        "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": "Stream, in real-time, roughly a 1% sample of all public Tweets.\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": [
  ]
}