Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Repair URL preview for tweets, may require a logged in Twitter account #7643

Closed
jryans opened this issue Jun 5, 2020 · 20 comments · Fixed by #7920
Closed

Repair URL preview for tweets, may require a logged in Twitter account #7643

jryans opened this issue Jun 5, 2020 · 20 comments · Fixed by #7920
Assignees
Labels
z-p2 (Deprecated Label)

Comments

@jryans
Copy link
Contributor

jryans commented Jun 5, 2020

As of a few days ago, URL previews for tweets have stopped working on matrix.org. Instead of a preview of the tweet, we get the following instead:

image

After discussing with @michaelkaye, he pointed out that other apps (such as Slack) seem to require a Twitter account for their tweet previewing integration. Perhaps something has changed on Twitter's side such that we'll also need to provide an account for Synapse to preview tweets?

@erikjohnston erikjohnston added z-p2 (Deprecated Label) improvement and removed improvement labels Jun 5, 2020
@auscompgeek
Copy link
Contributor

Somehow Facebook's URL previews still work for tweets.

@babolivier
Copy link
Contributor

I assume Facebook is also using a Twitter account to render tweet previews then.

@auscompgeek
Copy link
Contributor

I was curious so I took a closer look. I think Twitter are accommodating Facebook on their end. If you use Facebook's user-agent string, Twitter serves completely different HTML.

@rkfg
Copy link
Contributor

rkfg commented Jun 10, 2020

Can confirm, patched

headers={"Accept-Language": self.url_preview_accept_language},
like this:

        with self.media_storage.store_into_file(file_info) as (f, fname, finish):
            try:
                logger.debug("Trying to get preview for url '%s'", url)
                length, headers, uri, code = await self.client.get_file(
                    url,
                    output_stream=f,
                    max_size=self.max_spider_size,
                    headers={"Accept-Language": self.url_preview_accept_language,
                    "User-Agent": ["facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)"]},
                )

And now I have tweet previews again. It's not a solution but a nice workaround until a proper one appears.

@shaedrich
Copy link

Is matrix going to create an overall account to fix that for us all or merge this workaround any time soon?

@auscompgeek
Copy link
Contributor

I think the best way forward might be for Synapse to fetch the oEmbed from Twitter and massage that, rather than these sorts of workarounds. I suspect becoming a Twitter app might not be a great idea - the quotas would likely get exhausted very quickly.

@clokep
Copy link
Member

clokep commented Jun 15, 2020

Is matrix going to create an overall account to fix that for us all or merge this workaround any time soon?

The given workaround isn't really reasonable to merge into Synapse, we also don't want to add workarounds for specific sites like this.

Using something like oEmbed would likely be a sane way to improve the current embedding.

@shaedrich
Copy link

Are there arguments against doing that?

@rkfg
Copy link
Contributor

rkfg commented Jun 16, 2020

I myself would be against it, lol. It solves an issue for a single website (even though it's a very popular one) using a fake misleading user agent. It's clearly a temporary solution for server operators that need it to work right now but it's not general enough to make it to the upstream. It can also break previews for some other sites that, for example, block Facebook from indexing them (for whatever reason, like privacy).

There are many issues with this hack even though it works for now. It may stop working if tomorrow Twitter changes something again. Using oEmbed would be better of course, but from my understanding it would require custom requests that are different for every website that supports it. So it requires significant work anyway (to generalize this approach) and I wouldn't expect a non-hack solution soon considering it's p2.

@auscompgeek
Copy link
Contributor

Related: #2752

@neilisfragile
Copy link
Contributor

@ara4n take (paraphrased)
disable twitter previews for now
In future we could let users supply a twitter account to do the unfurling

@richvdh
Copy link
Member

richvdh commented Jun 22, 2020

@neilisfragile / @ara4n: surely using the oembed api link would be preferable to supplying an account?

@rkfg
Copy link
Contributor

rkfg commented Jun 22, 2020

Too bad Twitter doesn't provide oEmbed discovery as per https://oembed.com/#section4 so this API endpoint must be explicitly specified for Twitter in Synapse somewhere.

@auscompgeek
Copy link
Contributor

Would using Noembed be sensible?

@eternaleye
Copy link

eternaleye commented Jul 8, 2020

One thing pointed out by thelounge/thelounge#3602 is that the user-agent approach, in the great tradition of terrible user-agent hacks through history, is being used by Apple for all link previews in iMessage.

As a result, it may actually end up being a regrettable Schelling point of compatibility, as all sites which want link previews to work on iOS will add support for that user agent being used in this manner.

One notable aspect, here, is that unlike some of the alternative proposals (such as letting the user unfurl by providing a twitter account), this preserves anonymity.

@richvdh
Copy link
Member

richvdh commented Jul 9, 2020

for now we're just going to turn off url previews for twitter 🤷‍♂️

@rkfg
Copy link
Contributor

rkfg commented Jul 9, 2020

Is it possible to somehow opt-out from turning them off? I prefer to keep this workaround on my homeserver since it works for me and I post tweet links often.

@richvdh
Copy link
Member

richvdh commented Jul 9, 2020

@neilisfragile: were you envisaging that we just disable it for matrix.org (which we can do via config), or for everyone?

@richvdh
Copy link
Member

richvdh commented Jul 9, 2020

Would using Noembed be sensible?

I'm not familiar with that: it looks like it involves sending all preview requests via their hosted platform? I think many matrix users would be unhappy with that

@richvdh
Copy link
Member

richvdh commented Jul 9, 2020

ok, change of plan: we're going to try special-casing twitter url previews to use their oembed api. Hopefully that will solve the problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-p2 (Deprecated Label)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants