social-feed
social-feed copied to clipboard
Not showing Twitter image if more than one image added to tweet
If I get a tweet with one image in then it comes through fine, but if I get a tweet which has multiple images added then none of them come through. I don't need all of them just one would be fine. Not sure if this is a bug or whether I am doing something wrong here... any help would be great.
thanks
UPDATE:
I have found a fix for the issue. The problem was I needed to enable extended tweet mode. This was done on line 243:
"id=" + userid + "&count=" + options.twitter.limit + "&tweet_mode=extended",
With extended tweet mode enabled I can then get more tweet information. There was still an issue with retweets and shared tweets not showing the images and also tweet text wasn't showing for all. So I have modified the code slightly to check what type of tweet it is then use the correct media url.
unifyPostData: function(element) {
var post = {};
if (element.id) {
console.log(element);
post.id = element.id_str;
//prevent a moment.js console warning due to Twitter's poor date format.
post.dt_create = moment(element.created_at, 'dd MMM DD HH:mm:ss ZZ YYYY');
post.author_link = 'http://twitter.com/' + element.user.screen_name;
post.author_picture = element.user.profile_image_url_https;
post.post_url = post.author_link + '/status/' + element.id_str;
post.author_name = element.user.name;
post.message = element.full_text;
post.description = '';
post.link = 'http://twitter.com/' + element.user.screen_name + '/status/' + element.id_str;
if (options.show_media === true) {
console.log("retweeted_status: " + (typeof element.retweeted_status === "undefined"));
if (typeof element.retweeted_status !== "undefined") {
if (element.retweeted_status.entities.media && element.retweeted_status.entities.media.length > 0) {
var image_url = element.retweeted_status.entities.media[0].media_url_https;
if (image_url) {
post.attachment = '<img class="attachment" src="' + image_url + '" />';
}
}
}
else if (typeof element.quoted_status !== "undefined") {
if (element.quoted_status.entities.media && element.quoted_status.entities.media.length > 0) {
var image_url = element.quoted_status.entities.media[0].media_url_https;
if (image_url) {
post.attachment = '<img class="attachment" src="' + image_url + '" />';
}
}
}
else {
if (element.entities.media && element.entities.media.length > 0) {
var image_url = element.entities.media[0].media_url_https;
if (image_url) {
post.attachment = '<img class="attachment" src="' + image_url + '" />';
}
}
}
}
}
return post;
}