简体   繁体   中英

LinkedIn api - get company updates

I'm trying to fetch Company updates using LinkedIn's api. Somehow I can't get this to work. I can see console.log("On auth"); in the console, but after that nothing happens. It's like it stops with that function... No visible errors, no other console messages. Does anyone have an idea what could be wrong?

I'm using LinkedIn's test company which doesn't require any admin permissions.

My code is this:

<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> 

I ended up having this in head - added onLinkedInAuth to onLoad:

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

That did the trick.

Is this answer still works? I am trying to access the same but getting errors. Uncaught (in promise) TypeError: Cannot read property 'credentials' of null

<script type="text/javascript" src="https://platform.linkedin.com/in.js">
    api_key: 14-DIGIT-CLIENTID
    onLoad: onLinkedInLoad, onLinkedInAuth
    authorize: true 
</script>
<div id="displayUpdates"></div>
<script type="text/javascript">  
        function onLinkedInLoad() {  
            IN.Event.on(IN, "auth", onLinkedInAuth);  
            console.log("On auth");  
        }  
  
        function onLinkedInAuth() {  
            var cpnyID = CompanyIDHERE; //the Company ID for which we want updates  
            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,  
                    isComment = isContent;  
                if (isTitled) {  
                    var title = isContent.title;  
                } else {  
                    var title = "News headline";  
                }  
                var comment = share.comment;  
                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 + ">" + comment + "</a><br>";  
                    //el += "<li><img src='" + thumbnailUrl + "' alt=''>" + content + "</li>";  
                    el += "<li><div>" + content + "</div></li>";  
                }  
                console.log(share);  
            }  
            el += "</ul>";  
            document.getElementById("displayUpdates").innerHTML = el;  
        }  
    </script>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM