2014-11-21 39 views
3

我試圖讓使用JavaScript LinkedIn的追隨者數:如何獲得LinkedIn粉絲數量?

<div id="statusDiv">Result</div><script type="text/javascript" src="http://platform.linkedin.com/in.js"> 
       api_key: XXXXX 
onLoad: onLinkedInLoad 
authorize: true 
</script> 
<script type="text/javascript"> 
function onLinkedInLoad() { 
    IN.API.Raw("/companies/<<company_id>>:(num-followers)") 
.result(function(result) { document.getElementById("statusDiv").innerHTML = result.numFollowers; }) 
.error(function(error) { document.getElementById("statusDiv").innerHTML = error }); 
} 
</script> 

但這並不爲我工作。

回答

1

你的代碼看起來不錯。檢查您的JavaScript控制檯是否有錯誤。我懷疑你的LinkedIn應用程序設置中沒有正確配置你的「Javascript API域」值。

下面是相同的代碼的一個稍微乾淨的版本,我只是看到了一個正確配置的LinkedIn應用程序成功運行:

<html> 
    <head> 
    <script src="http://platform.linkedin.com/in.js" type="text/javascript"> 
     api_key: xxxxxxxxxxxxxx 
     onLoad: onLinkedInLoad 
     authorize: true 
    </script> 

    <script type="text/javascript"> 
     function onLinkedInLoad() { 
      IN.API.Raw("/companies/1337:(num-followers)").result(onSuccess).error(onError); 
     } 

     function onSuccess(data) { 
      document.getElementById("statusDiv").innerHTML = data.numFollowers; 
     } 

     function onError(error) { 
      console.log(error); 
     } 
    </script> 
    </head> 

    <body> 
    <div id="statusDiv">Result</div> 
    </body> 
</html> 
相關問題