1

I have a project using "kotlinFrontend" to create a really nice react front end written in kotlin. How do i get access to the facebook js sdk (it is usually done withing script tags)

I have this code on my HTML template that includes the generated bundle containing

<script>
window.fbAsyncInit = function() {
    FB.init({
        appId      : '503127050093992',
        cookie     : true,
        xfbml      : true,
        version    : 'v3.2'
    });
    FB.AppEvents.logPageView();
};

(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'));

Inside my kotlin react code, how would i then be able to access the creatd FB obj?

1 Answer 1

0

Use external var FB

Type-safe way:

  1. Get typescript definitions from facebook-js-sdk
  2. Use ts2kt to convert it to Kotlin. Generated files might have some errors, but they are usually easy to fix.
  3. Add these files to your project. You'll get external var FB: facebook.FacebookStatic that you can access.

Unsafe way:

  1. Declare external var FB: dynamic
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.