Commit 36d8ff9f authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega

Use an undocumented parameter to always fetch extended tweets from twitter

parent 1e10d543
......@@ -97,7 +97,11 @@ class TwitterAccount extends Account {
// Get a few of the last statuses in the main timeline
this._tw.get('statuses/home_timeline', {
count: 100
count: 100,
// This undocumented option makes the tweets have the full text,
// and never be truncated.
tweet_mode: 'extended'
// count: 10
}, (err, msgs, response)=>{
if (err) {
......@@ -203,7 +207,11 @@ class TwitterAccount extends Account {
// quoted_status), and normalize some stuff (to make different platforms
// see the same data from different platforms)
_normalize(msg, channel) {
if (('id_str' in msg) && ('contributors' in msg) && ('text' in msg)) {
// if (('id_str' in msg) && ('contributors' in msg) && ('text' in msg)) {
if (('id_str' in msg) && (
('contributors' in msg) && ('text' in msg) || // Non-extended
('full_text' in msg) // Extended
)) {
// This looks like a tweet
// console.log('tweet is truncated: ', msg.truncated);
......@@ -235,7 +243,10 @@ class TwitterAccount extends Account {
// console.log('Truncated ', msg.text, ' - fetching full from id ', msg.id_str);
return {
timestamp: Date.parse(msg.created_at),
itemPromise: this._tw.get('statuses/show/', { id: msg.id_str }).then((full)=>{
itemPromise: this._tw.get('statuses/show/', {
id: msg.id_str,
tweet_mode: 'extended'
}).then((full)=>{
if (full.truncated) {
// After requesting individual tweet, got it truncated also
// console.log('Got full but still truncated. From: «', msg.text , '» into: ', full);
......@@ -247,7 +258,13 @@ class TwitterAccount extends Account {
}
}
if ((!msg.text) && msg.full_text) {
// This looks like an extended tweet, fetched via a "tweet_mode=extended" REST API call
msg.text = msg.full_text;
}
if (msg.extended_tweet) {
// This looks like an extended tweet, fetched via a realtime stream
// return this._normalize(Object.assign({}, msg.extended_tweet, msg);
msg.text = msg.extended_tweet.full_text;
msg.entities = msg.extended_tweet.entities;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment