Thread: Bluesky Embeds
View Single Post
Old 03-02-2025, 01:40 AM   #31
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
Yeah that's basically what I had in mind just didn't really know how to do the Javascript well.

I did also find this: https://github.com/itteco/iframely

Which looks like it might work plus support a lot of different things all at once, was going to take a look at it.
Ok, did some testing today. A couple errors in the code I posted above (I'll post fixed code below), however, there was a more fundamental issue, which is that bluesky's oembed does not support client-side integration. A call to their oembed endpoint using javascript/xmlhttprequest will return a cors error. The request needs to be made using a server-side call.

For some oembeds, you can use jsonp to get around the cors error. But that requires the oembed implementation to support jsonp, and bluesky's does not.

So there were only two alternatives:

1) Implement the oembed call server side. I'm unfamiliar with what vbulletin supports regarding customizing the output of posts server-side, so not sure what would be involved here.

2) Use a local server-side proxy that the page javascript will call. The proxy will take the bluesky oembed url, and return the json result. Since it's server-side, it won't run into the cors issue.

I tried to implement #2, and I think I have it working.

I slightly modified (simplified) a php proxy file I got from here and renamed it proxy.php
Spoiler!


I then created a test page that adds the following div:

PHP Code:
<div class=bsky url="https://bsky.app/profile/aoc.bsky.social/post/3lapo7x44ws2k"/> 
I'm placing the entire url instead of just the id since the profile also has to be passed in. It's probably easier to pass the entire url instead of cutting out the profile and id.

I then add 2 scripts at the end of the page. One is the script that calls oembed:
Spoiler!


The other is the script that is returned by bluesky's oembed. I'm adding the blockquote+script using innerHTML above, but using innerHTML does not execute the script. So I took the script and placed it in its own script tags, and made a call to the script directly after the innerHTML replacement.
Spoiler!


Finally, here is the full context of my test page.
Spoiler!

I was able to "embed" the bluesky post directly into my page using this method.

To add this to CP, you will have to:
1) add the proxy.php (maybe vbulletin already has its own method to do a proxy, in which case this isn't needed, and a small modification of the first script has to be done to call the built-in proxy properly).
2) Add the two scripts at the bottom of each page. First one converts the one-line bsky div into a blockquote. Second one converts the blockquote into a properly formatted bluesky iframe.
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post: