如何使用脚本加载器加载LinkedIn Javascript API库?

wil*_*age 13 javascript linkedin

LinkedIn Api建议您加载他们的javascript库,如下所示:

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: your_api_key_goes_here
</script>
Run Code Online (Sandbox Code Playgroud)

我想知道如何使用脚本加载器(例如RequireJS或LABJS)加载它.似乎库从脚本标记中提取了api密钥.在我看来,这似乎是一种非常奇怪的方式!

我更喜欢使用脚本加载器加载库,但似乎无法在不使用建议的方法的情况下找到如何插入api_key.

官方说明在这里

有人有主意吗?

Ada*_*erg 17

来自:https://developer.linkedin.com/documents/general-methods

异步加载

为避免在页面中遇到竞争条件,您可以异步加载框架.

如果您的页面使用JQuery,则以下代码将起作用:

$(document).ready(function() {
    $.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
        IN.init({
            onLoad: "myOnloadFunction"
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

否则,你需要这样的东西:

<script type="text/javascript" src="http://platform.linkedin.com/in.js?async=true"></script>
<script type="text/javascript">
    IN.init({
        onLoad: "myOnloadFunction"
        // any other parameters you'd normally put beneath the script element would be here
    });
</script>
Run Code Online (Sandbox Code Playgroud)

  • 那我的API密钥在哪里? (3认同)