Problem/Motivation
Back on May 24, 2016, Twitter made a couple of announcements about upcoming changes to tweet formats:
Then on September 26, 2017, they made another one:
The first two were about doing more with the same 140 characters. The third one is about having up to 280 characters. In making those changes, Twitter updated their tweet object and added tweet "modes." The two modes are "Compatibility" and "Extended." The details of modes and the related changes to the objects can be found on the Tweet updates page.
Due to those changes, the creation of a number of seemingly unrelated issues in this queue about missing or incomplete tweet data have been created. Also, there have been situations where fixing the problem for one tweet mode breaks it or something else for the other.
The upshot of those changes for this module is that the code now needs to take into account the possibility that a tweet may be a "Classic" tweet in compatibility mode or an "Extended" tweet in extended mode, and the appropriate mode needs to be used to retrieve all the relevant data.
At some point in the future, Twitter plans on making these changes the de facto standard:
In the "Rendering modes" section of the Tweet updates page:
In the future, an additional announcement will be made when the time is right to make a change for the rendering mode to default to extended mode.
In the "Standard streams" section of the Tweet updates page:
In the future, a date for a switchover to extended mode will be announced, after which time apps should be able to process the newer Tweet payloads.
Until then, however, I do not think we can completely ignore the compatibility mode tweets.
Proposed resolution
Implement extended_mode tweets in this module.
Things to consider when implementing this:
- Creating the relevant URL in create_url() in twitter.lib.php.
- Updating the calls a Twitter API endpoint in call() in twitter.lib.php.
- Accounting for tweet data in different places in the TwitterStatus constructor in twitter.lib.php (for 7.x-5.x). (This is in a differnt place in the 7.x-6.x branch.)
- Possibly also accounting for tweet data in different places twitter_status_save() in twitter.inc.
I believe that if the data retrieved from Twitter can be placed in this module's twitter objects early enough on in the API call process, very little of the rest of the module will need to be touched, but that yet remains to be seen.
This will need to be done for both 7.x-5.x and 7.x-6.x branches.
Remaining tasks
- Fix the issue
- Create a patch
- Review the patch
- Commit the patch
User interface changes
To be determined.
API changes
To be determined.
Data model changes
To be determined.
Original report by iancawthorne
(Previous title: Sometimes Tweet images show, sometimes they don't)
I've tried with various accounts. With images attached to a Tweet in the format https://pbs.twimg.com/media/image-name.jpg, sometimes the image will be there, sometimes it won't. This seems to apply inconsistently for both Tweets and Re-tweets.
Checking the entities column of the twitter table, it looks like the image doesn't get added to here when it doesn't work. But it's there in [media] when it does.
As of yet, I've been unable to work out "why" it sometimes does not pull the image through.
Comment | File | Size | Author |
---|---|---|---|
#25 | twitter_implement-extended-mode-tweets_7x5x_2907103_25.patch | 5.1 KB | oadaeh |
#19 | twitter_implement-extended-mode-tweets_2907103_19.patch | 4.73 KB | oadaeh |
|
Comments
Comment #2
iancawthorne CreditAttribution: iancawthorne commentedComment #3
iancawthorne CreditAttribution: iancawthorne commentedI have worked out what the problem is here. The api call needs to have "?tweet_mode=extended" added on the end.
This is found in:
function create_url()
This line:
$url = variable_get('twitter_api', TWITTER_API) .'/1.1/'. $path . $format;
Becomes:
$url = variable_get('twitter_api', TWITTER_API) .'/1.1/'. $path . $format.'?tweet_mode=extended';
Would the preferred outcome to this be to provide a patch as per above, or should there be a way to add parameters in a less hard coded way?
Comment #4
iancawthorne CreditAttribution: iancawthorne commentedHowever, when "tweet_mode=extended" is specified, the tweet message itself becomes blank.
Comment #5
Melju CreditAttribution: Melju commentedWhen you change your URL to be "extended".
You have to change this line :
to this :
The text will show up again with the pictures this time ;)
Comment #6
patgibbs CreditAttribution: patgibbs commentedHas anyone managed to find a workable solution to this issue?
I'm dealing with a couple of organisations whose Twitter feeds contain a lot of visual material - it is critical that the organisation's website reflects this in its Twitter feed. However, the Twitter module in its current state only displays a fraction of the feed's images in what appears to be a random fashion.
iancawthorne mentioned above that the 'tweet_mode=extended' parameter was missing in the twitter.lib.php file (although this proved to be unreliable for other reasons as he mentioned). This thread states that the images are broken when links are included in the message body (although this has not proved to be the case in my experience, since several of our tweets that have included links also display their images).
I'm afraid I'm not adept at PHP enough to look into this myself, but I feel that this is a significant bug that needs addressing - images are a vital part of Twitter!!
Thanks in advance.
Comment #7
patgibbs CreditAttribution: patgibbs commentedComment #8
alex_daniels CreditAttribution: alex_daniels commentedI've found a workable fix (although I should say I'm on 7.x-6.x-dev and not 5.x-dev) and created a patch for the 5.x-dev version using the same fix that worked on my end.
Hope this works for anyone who is still looking for a fix.
Comment #9
alex_daniels CreditAttribution: alex_daniels commentedI've found a workable fix (although I should say I was working on 6.x-dev not 5.x-dev).
Comment #10
oadaeh CreditAttribution: oadaeh at Hook 42 commented@iancawthorne and @patgibbs are there any error notices in watchdog (/admin/reports/dblog) when those tweets without images get pulled in?
Comment #11
iancawthorne CreditAttribution: iancawthorne commentedNo error notices in the logs no. I see three success notices in the logs, which are:
Finished downloading tweets.
Downloaded 20 tweets for the xxxxxxxx account.
Starting to download tweets.
Comment #12
oadaeh CreditAttribution: oadaeh at Hook 42 commentedI did some research into the extended tweet mode when I posted my last comment and I did quite a bit more tonight, and I agree with @iancawthorne that the problem is due to the change in tweet structure as outlined in this post: https://developer.twitter.com/en/docs/tweets/tweet-updates
The changes for supporting extended tweet modes will be more extensive than just those two lines, however, as several things in the structure of the tweet object got shifted a bit and multiple places in the code will need to be checked and verified they still work correctly.
I have begun work on it, and I would have gotten farther, but I wanted to see what the future for compatible tweets were, and I finally found it in the "Rendering modes" section of the document I linked to:
EDIT: I will be updating this ticket with more information about the actual scope of the issue later on.
Comment #13
oadaeh CreditAttribution: oadaeh at Hook 42 commentedI marked #2869088: Tweets doesn't display images when include links as a duplicate of this ticket.
Comment #14
oadaeh CreditAttribution: oadaeh at Hook 42 commentedComment #15
oadaeh CreditAttribution: oadaeh at Hook 42 commentedComment #16
oadaeh CreditAttribution: oadaeh at Hook 42 commentedI have already begun working on this, and I have updated both the create_url() and call() functions in twitter.lib.php for both branches. I have also updated the TwitterStatus constructor in twitter.lib.php for the 7.x-5.x branch, but I am still looking for where or how that is done in the 7.x-6.x branch, since the code is not the same. I have yet to look at anything beyond that.
Comment #17
oadaeh CreditAttribution: oadaeh at Hook 42 commentedHere is a patch to implement extended_mode tweets on the 7.x-6.x branch. It also includes something similar to what I posted in #2803293-15: Fatal Error During Cron because I think it might be related.
Comment #18
oadaeh CreditAttribution: oadaeh at Hook 42 commentedHere is a patch to implement extended_mode tweets on the 7.x-5.x branch. It also includes something similar to what I posted in #2803293-15: Fatal Error During Cron because I think it might be related.
Comment #19
oadaeh CreditAttribution: oadaeh at Hook 42 commentedHere's the real patch for 7.x-6.x.
Comment #20
oadaeh CreditAttribution: oadaeh at Hook 42 commentedComment #21
hosef CreditAttribution: hosef at Hook 42 commentedI tested the patch for the 7.x-6.x branch on my local environment.
The patch applied cleanly. The code changes looked good and the documentation changes were easy to understand. I was able to successfully download tweets from my twitter account.
Marking as RTBC.
Comment #22
andrey.troeglazov CreditAttribution: andrey.troeglazov at DrupalJedi commentedComment #24
andrey.troeglazov CreditAttribution: andrey.troeglazov at DrupalJedi commentedThanks, @oadaeh and @hosef for patch and testing, I have reviewed the patch it seems to be ok for me. I have commited it to 7.6 branch.
Comment #25
oadaeh CreditAttribution: oadaeh at Hook 42 commentedI also intended to attach a patch for the 7.x-5.x branch, but instead I attached one for the other issue. (Sorry for the confusion.)
The patch I am attaching to this comment is the correct patch to the 7.x-5.x branch to apply the same fix as has now been applied to the 7.x-6.x branch.
Comment #27
oadaeh CreditAttribution: oadaeh at Hook 42 commentedThe tests are failing because CTools is broken.
Comment #28
oadaeh CreditAttribution: oadaeh at Hook 42 commentedComment #30
andrey.troeglazov CreditAttribution: andrey.troeglazov at DrupalJedi commentedLooks good for me, commited. Thank you.
Comment #31
oadaeh CreditAttribution: oadaeh at Hook 42 commentedExcellent. Thank you. Now we need to see how many open issues can be closed because of this. :)
Comment #33
Katy Jockelson CreditAttribution: Katy Jockelson commentedCan you please confirm which branches (for D7) this has been committed to?
I'm not getting images or retweets with either the 7.x-6.2 or the 7.x-6.x-dev version.
I see the note at the top of the module page 'View embedded images media from tweets (not in 7.x-6.x branch yet).' - does that mean we should use 5x if we want to see images and retweets?
Thanks a lot
Comment #34
pixel6 CreditAttribution: pixel6 commentedIt works! Thanks for all.