I would like to add the facebook Oembed page to my vue app. I did all the facebook process to get access to my oembed page properly. It works and it returns me an html with this structure :
<div id="fb-root"></div>
<script async="1" defer="1" crossorigin="anonymous" src="https://connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v12.0" nonce="jvnA38OI"></script><div class="fb-page" data-href="urlToMyFacebookPage" data-small-header="" data-adapt-container-width="1" data-hide-cover="" data-show-facepile="1" data-show-posts="1" data-width="480" data-height="800"><blockquote cite="urlToMyFacebookPage" class="fb-xfbml-parse-ignore"><a href="urlToMyFacebookPage">My Facebook Page</a></blockquote></div>
So from this point everything seems ok. Then I want to show this html in my app but I cant find a way to make it load the actual facebook page. The best result I had was a link to the facebook page.
So here is what I've done in my app :
- Axios requester for facebook API calls
- Add a Facebook init.js file to load the facebook sdk before the app as the following code
init-facebook.js :
const facebookAppId = process.env.VUE_APP_FACEBOOK_APP_ID
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function initFacebookSdk() {
return new Promise(resolve => {
// wait for facebook sdk to initialize before starting the vue app
window.fbAsyncInit = function () {
FB.init({
appId: facebookAppId,
cookie: true,
xfbml: true,
version: 'v12.0'
})
FB.AppEvents.logPageView()
console.log('facebook logged')
resolve()
};
// load facebook sdk script
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0]
if (d.getElementById(id)) { return }
js = d.createElement(s); js.id = id
js.src = 'https://connect.facebook.net/en_US/sdk.js'
fjs.parentNode.insertBefore(js, fjs)
}(document, 'script', 'facebook-jssdk'))
})
}
main.ts :
initFacebookSdk().then(startApp)
function startApp() {
createApp(App)
.use(router)
.mount('#app')
}
Then in the component I want to get the facebook page I called the facebook API from the requester, I do get the result in the first code block. I store the html in a reactive variable (with the vue Ref) Then I tried this :
- Add the html variable directly in my component html -> Result : Shows the html as a string in my component
- Add the html in a div with a v-html -> Result : Shows a link to the facebook page
I don't know what am I missing to show the page properly. Does anyone can help me with it ? Thanks !
FB.XFBML.renderto make that happen.parse, notrender. Is something like stackoverflow.com/a/61462872/1427878 not working for you?