-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support image previews for Twitter oEmbed URL Previews #8022
Comments
I'm not really in favour of this for two reasons:
The Twitter API suggests that clients include https://platform.twitter.com/widgets.js and run |
I'm going to close this because I think we've agreed that this isn't the right approach 🙂 |
It's actually easy to do and doesn't require all of that. https://mau.dev/maunium/synapse/-/commit/fe01ce7cf786378f72f741c80b6183674aeada50 It seems that has been decided against for some reason but I'm just adding a comment here so at least it is mentioned somewhere on the repo. |
For those coming here in the future, Synapse already sends a User-Agent string of It seems that the solution @aaronraimist works because twitter allows previews by programs with "bot" in their user-agent string. We're not sure whether we want to add this to the user-agent string, especially if it's not standard practice and twitter-specific. One may suggest allowing the URL preview UA to be configurable, but having to tell users to change this setting to get services like twitter working isn't a great situation to be in. Given the above there's not an easy path forward here. |
Bot in the user agent doesn't seem like that much of a hack to me. For example #1859 was asking to put bot in the UA string back in 2017 just to show that it was in fact a bot making the requests. Right now the current situation will never work so even if it only worked temporarily after making this change that's still an improvement. You don't have to guarantee that Twitter previews are going to continue to work after making this change. It can just happily work, until maybe in the future they change something and it stops working. |
We don't want to modify the UA header for a twitter-specific reason. However, if putting "bot" in the URL is something industry-wide, or as you say to indicate that it's a request originating from a bot, then it'd be a good reason to do so. What do other link-fetching services do? After some discussion in #synapse-dev, I'm more favourable towards the configurable UA option, although I do realise that it wouldn't solve the problem for twitter by default. |
I don't know if it is a standard but it doesn't seem uncommon. For example most of Google's crawlers have the word bot in the user agent https://support.google.com/webmasters/answer/1061943?hl=en and like the Wikipedia article for user agents says
As a reference for that it is just linking to a blog post but it does seem like something that some people recommend. https://en.wikipedia.org/wiki/User_agent#Format_for_automated_agents_(bots) |
To help fix twitter embedding issues, we've just added support for oEmbed in capturing URL previews. We now use this for previewing twitter links (by default), and we can now receive tweet text without problems. However, twitter does not return any image data for a tweet in its oEmbed response:
You'll notice that the
html
key has apic.twitter.com
URL in it. However, this just leads us to the tweet HTML, and extracting it from this HTML is too twitter-specific anyways.However, the HTML returned here is the exact same (minus being encoded) as what's shown on publish.twitter.com for this tweet. You can see that this HTML renders into a nice little standardised preview of the tweet. Part of this HTML is a JS script that gets loaded (
platform.twitter.com/widgets.js
) that will actually do most of the magic render the tweet.Theoretically, after rendering this HTML output locally, we can just run our standard URL preview code over it and extract an image!
Thus my proposal for support Twitter image embeds with oEmbed that is still generic is to:
photo
orvideo
response type is used, orthumbnail*
keys are provided.html
key.html
key exists, render securely and run URL preview code over it.At the moment this is all theory, I haven't tested it in code yet.
The text was updated successfully, but these errors were encountered: