FB init function gives wrong version error

后端 未结 20 1342
故里飘歌
故里飘歌 2020-12-08 18:18

I\'m using the Facebook JS sdk, and I have created a new App today. Everything is configured properly. Using init function like:

window.fbAsyncInit = functio         


        
20条回答
  •  再見小時候
    2020-12-08 18:49

    Make sure you're using https:// in the URL

    js.src = "https://connect.facebook.net/en_US/sdk.js";
    

    I would not have believed this either, but the only difference between what Facebook has in their current sample code and what I have is https:// instead of // for the url.

    Updating to be https:// seems to have fixed it for me and I cannot duplicate the error.

    Also if you're doing any checks elsewhere in your code to see if FB is defined make sure to check if (window.FB) and not if (FB) or you will get an error.

    // call after manually adding DOM nodes containing FB widgets
    if (window.FB)
    {
        window.FB.XFBML.parse()
    }
    

    If you're using typescript you need to add something like this:

    interface Window
    {
        FB: IFacebook;
    }
    
    interface IFacebook
    {
        XFBML: any;
        ui: any;
        getLoginStatus(callback: (response: { status: string }) => any);
        login(callback: (response) => any, options: any);
        logout(callback: () => any);
        Event: any;
        api(url: string, callback: (response: any) => any);
    }
    

提交回复
热议问题