2016-01-05 89 views
1

我試圖使用LinkedIn的api獲取公司更新。不知何故,我無法得到這個工作。我可以看到console.log(「On auth」);在控制檯中,但之後沒有任何反應。這就像它停止與該功能...沒有可見的錯誤,沒有其他控制檯消息。有沒有人有一個想法可能是錯的?LinkedIn api - 獲取公司更新

我使用LinkedIn的測試公司,它不需要任何管理權限。

我的代碼是這樣的:

<head> 
    <script type="text/javascript" src="https://platform.linkedin.com/in.js"> 
    api_key: 14characters 
    onLoad: onLinkedInLoad 
    authorize: true 
    </script> 
</head> 

<body> 
    <div id="displayUpdates"></div> 

    <script type="text/javascript"> 
     function onLinkedInLoad() { 
      IN.Event.on(IN, "auth", onLinkedInAuth); 
      console.log("On auth"); 
     } 
     function onLinkedInAuth() { 
      var cpnyID = 2414183; //LinkedIn's testDevCo 
      IN.API.Raw("/companies/" + cpnyID + "/updates?event-type=status-update&start=0&count=10&format=json") 
       .result(displayCompanyUpdates); 
       console.log("After auth"); 
     } 
     function displayCompanyUpdates(result) { 
      var div = document.getElementById("displayUpdates"); 
      var el = "<ul>"; 
      var resValues = result.values; 
      for (var i in resValues) { 
       var share = resValues[i].updateContent.companyStatusUpdate.share; 
       var isContent = share.content; 
       var isTitled = isContent, 
        isLinked = isContent, 
        isDescription = isContent, 
        isThumbnail = isContent; 
       if (isTitled) { 
        var title = isContent.title; 
       } else { 
        var title = "News headline"; 
       } 
       if (isLinked) { 
        var link = isContent.shortenedUrl; 
       } else { 
        var link = "#"; 
       } 
       if (isDescription) { 
        var description = isContent.description; 
       } else { 
        var description = "No description"; 
       } 
       if (isThumbnailz) { 
        var thumbnailUrl = isContent.thumbnailUrl; 
       } else { 
        var thumbnailUrl = "http://placehold.it/60x60"; 
       } 
       if (share) { 
        var content = "<a target='_blank' href=" + link + ">" + title + "</a><br>" + description; 
        el += "<li><img src='" + thumbnailUrl + "' alt=''>" + content + "</li>"; 
       } 
       console.log(share); 
      } 
      el += "</ul>"; 
      div.innerHTML = el; 
     } 
     </script> 
</body> 
+0

如果你在'onLinkedInAuth()'的開頭放了一個'console.log()',它會記錄下來嗎? onload \t **您希望SDK在其成功加載自身後執行的Javascript函數名稱的逗號分隔列表**。 – Craicerjack

+0

感謝您的回覆。不,它不產生任何輸出onLinkedInAuth的'開始()'... – Meek

+0

所以'onLinkedInAuth()'不被調用,所以你的問題是與該行'IN.Event.on(IN,「權威性」 ,onLinkedInAuth);'。沒有使用linkedin的API所以抱歉不能幫助超越 - 你有沒有嘗試過使用不同的'eventName'而不是「auth」 – Craicerjack

回答

2

我結束了在頭,具有本 - 添加onLinkedInAuth到的onLoad:

<script type="text/javascript" src="https://platform.linkedin.com/in.js"> 
    api_key: 14characters 
    onLoad: onLinkedInLoad, onLinkedInAuth 
    authorize: true 
</script> 

該訣竅。

+0

如何找到公司ID? –

+0

這是在該公司的網址在LinkedIn最終的數字,eghttps://www.linkedin.com/company/3724/ - > id爲3724 – Meek

+0

但這個ID是不工作,回報得到錯誤... 。@ Meek –