Onebox Twitter embedding


(Dean Taylor) #12

Twitter now support oEmbed for their timelines via their API:

You can also request omit_script via the API.

Not sure if it fits with Discourse posts - but seems relevant here.


(Jeff Atwood) #13

Sure @techapj can you see what happens in this case?


(Arpit Jalan) #14

This is awesome! We may finally be able to onebox fancy tweets without needing Twitter API access.

Added on my list to look into next week.


(Arpit Jalan) #15

So I looked into it today and it’s still not usable. :frowning:

Here is a comparison:

Twitter onebox with API key:

Twitter onebox without API key:

Twitter onebox using new oEmbed endpoint (without script):

Twitter onebox using new oEmbed endpoint (with script):

Now since we can’t use oEmbed with script, I think for now we will have have to rely on OpenGraph data in case Twitter API key is not present.


(Dean Taylor) #16

Sad times…

My post was regarding “timelines” as a new type of embed - But these aren’t “timelines”…

… I had already thought you had compared single tweet embeds.

But very good to see it visually - thanks.


(Arpit Jalan) #17

Ah, I see. Just looked at that, it also depends on JavaScript, and inserting script tag in our DOM isn’t supported.


(Dean Taylor) #19

I just had a quick look at the output from the API, it’s pretty poor - it does seem to require JavaScript to do anything :frowning:

plain request

{
    "url": "https:\/\/twitter.com\/TwitterDev",
    "title": "",
    "html": "\u003Ca class=\"twitter-timeline\" href=\"https:\/\/twitter.com\/TwitterDev\"\u003ETweets by TwitterDev\u003C\/a\u003E\n\u003Cscript async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"\u003E\u003C\/script\u003E",
    "width": null,
    "height": null,
    "type": "rich",
    "cache_age": "3153600000",
    "provider_name": "Twitter",
    "provider_url": "https:\/\/twitter.com",
    "version": "1.0"
}

omit_script request

{
    "url": "https:\/\/twitter.com\/TwitterDev",
    "title": "",
    "html": "\u003Ca class=\"twitter-timeline\" href=\"https:\/\/twitter.com\/TwitterDev\"\u003ETweets by TwitterDev\u003C\/a\u003E\n",
    "width": null,
    "height": null,
    "type": "rich",
    "cache_age": "3153600000",
    "provider_name": "Twitter",
    "provider_url": "https:\/\/twitter.com",
    "version": "1.0"
}

As all it really does is allow you to exclude the scripts from the embeds to include it once in the page :sadpanda:

Looks like I hoped for too much.


(Scott Rubin) #20

While the full on Twitter embedding would be nice, if that’s not possible can we at least have images appear? A lot of people post Tweets solely because of the images, and forcing users to leave the site just to see the image(s) is not very friendly.

Instagram embedding actually has the opposite problem right now. It only embeds the image, and you would never know that the image was actually an embedded Instagram post. It should at least include the caption and the Instagram username.


Instagram oneboxing
(Jeff Atwood) #21

This already works, you just need to set up Twitter logins to get a valid API key.


(Scott Rubin) #22

Oh, thanks! Is it possible to do that without actually allowing Twitter logins?


(Arpit Jalan) #23

Disable enable twitter logins and just provide twitter consumer key & twitter consumer secret.


(Scott Rubin) #24

Tried it. It didn’t work. Embedded tweets still do not contain images.


#25

Some long tweets with images don’t work

Shorter tweets with images works

It exists since the new twitter policy regarding links and images in the 140 characters count


(David Taylor) #26

I’ve just submitted a PR which should fix this:


(Chris Beach) #27

@david - thank you! We do a lot of Twitter oneboxing and found the truncation very annoying.


(Tim) #28

This is terrific - my forum users really need this.

Is this merged into a future release or something we have to do to modify in our existing installations?


#29

Just upgrade on latest version, it should be good :

  • via yourforum.com/admin/upgrade
  • or SSH into your server and do these commands :

cd /var/discourse
git pull
./launcher rebuild app

I don’t think you need to add the twitter consumer key and twitter consumer secret in your admin settings but I’m only 99% sure


(David Taylor) #30

Yep - it’s all merged into master and working great on my forum

I’m afraid you will need to add these keys to your site settings - the data is fetched via the twitter API rather than opengraph/oembed.


#31

It’s always the 1% left


(Arpit Jalan) #32

I just pushed a small improvement for Twitter onebox. The onebox will now show like and retweet count.