[英]How can I load the LinkedIn Javascript API library with a script loader?
The LinkedIn Api suggests you load their javascript library like this: LinkedIn Api建议您加载他们的javascript库,如下所示:
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: your_api_key_goes_here
</script>
I want to know how I can load this using a script loader (eg. RequireJS or LABJS). 我想知道如何使用脚本加载器(例如RequireJS或LABJS)加载它。 It seems the library extracts the api key from within the script tags.
似乎库从脚本标记中提取了api密钥。 This seems like a pretty weird way of doing it in my opinion!
在我看来,这似乎是一种非常奇怪的方式!
I would prefer to load the library using a script loader, but can't seem to find out how to insert the api_key without using the suggested method. 我更喜欢使用脚本加载器加载库,但似乎无法在不使用建议的方法的情况下找到如何插入api_key。
The official instructions are here 官方说明在这里
Anyone have any ideas? 有人有主意吗?
From: https://developer.linkedin.com/documents/general-methods 来自: https : //developer.linkedin.com/documents/general-methods
Async Loading 异步加载
To avoid encountering race conditions in your page, you can load the framework asynchronously. 为避免在页面中遇到竞争条件,您可以异步加载框架。
If your page uses JQuery, the following code will work: 如果您的页面使用JQuery,则以下代码将起作用:
$(document).ready(function() {
$.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
IN.init({
onLoad: "myOnloadFunction"
});
});
});
Otherwise, you need something like this: 否则,你需要这样的东西:
<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>
Check this out 看一下这个
if(typeof IN === 'undefined'){ //if it is already included don't include that
$.getScript('//platform.linkedin.com/in.js', function(data, textStatus){
IN.init({
api_key: 'YOUR_API_KEY',
onLoad: function(){
alert("Fully Loaded");
}
});
});
}
As noted by @AdamTrachtenberg you need to use the async version of the API: http://platform.linkedin.com/in.js?async=true 正如@AdamTrachtenberg所述,您需要使用API的异步版本: http ://platform.linkedin.com/in.js?async = true
next you will have to call the In.init()
upon load of the API JS. 接下来,您必须在加载API JS时调用
In.init()
。
You should do so in the callback function of you script loader. 您应该在脚本加载器的回调函数中执行此操作。
You may provide your API Key as a param to In.init()
您可以将您的API密钥作为
In.init()
的参数提供
Note: that you do not need to pass a callback function onLoad
to In.init()
注意:您并不需要一个回调函数传递
onLoad
到In.init()
a post i wrote about the same 我写的一篇文章也是如此
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.