skip to Main Content

I am using twitter stream API with Javascript in order to collect tweets. The problem is that I am not using the extended mode and I don’t get the full tweet when it is greater than 140 characters. I have searched info and I discovered that I need to pass tweet_mode=extended in the request and the response will contain a full_text which is the tweet complete. The problem is that I don’t know where to write tweet_mode=extended. This is my code:

    twitter.stream('statuses/filter', {track: word, function (stream) {
            stream.on('data', function (tweet) {
                 console.log(tweet.text)
            });
            stream.on('error', function (error) {
                console.log("error:", error);
            })
        })

2

Answers


  1. Unfortunately the streaming API does not have the option to add the tweet_mode param

    Documentation here: https://developer.twitter.com/en/docs/tweets/tweet-updates

    This paragraph is of note to your concern:

    The Streaming API does not provide the same ability to provide query
    parameters to configure request options. Therefore, the Streaming API
    renders all Tweets in compatibility mode at this time.

    Streaming API consumers should update their code to first check for
    the presence of the extended_tweet dictionary, and use that in
    preference to the truncated data as is applicable for their use case.
    When extended_tweet is not present, they must fall back to using the
    existing fields.

    Login or Signup to reply.
  2. As Van said, tweets in streaming API are mixed. So you can try this :

    twitter.stream('statuses/filter', {track: word, function (stream) {
            stream.on('data', function (tweet) {
                 let text = tweet.extended_tweet?tweet.extended_tweet.full_text:tweet.full_text?tweet.full_text:tweet.text;
                 console.log(text)
            });
            stream.on('error', function (error) {
                console.log("error:", error);
            })
        })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search