LinkedIn api - 获取公司更新
LinkedIn api - get company updates
我正在尝试使用 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>
我最终想到了这个 - 添加 onLinkedInAuth
到 onLoad:
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: 14characters
onLoad: onLinkedInLoad, onLinkedInAuth
authorize: true
</script>
成功了。
我正在尝试使用 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>
我最终想到了这个 - 添加 onLinkedInAuth
到 onLoad:
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: 14characters
onLoad: onLinkedInLoad, onLinkedInAuth
authorize: true
</script>
成功了。