LinkedIn api - 获取公司更新

时间:2016-01-05 14:26:27

标签: javascript linkedin linkedin-api

我试图使用LinkedIn的api获取公司更新。不知怎的,我无法让它发挥作用。我可以看到console.log(" On auth");在控制台中,但之后没有任何反应。就像它停止使用该功能一样......没有可见错误,没有其他控制台消息。有没有人知道可能出现什么问题?

我使用的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> 

1 个答案:

答案 0 :(得分:2)

我最终得到了这个 - 将onLinkedInAuth添加到onLoad:

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

这就是诀窍。