Javascript LinkedIn api-获取公司更新
我正在尝试使用LinkedIn的api获取公司更新。不知怎么的,我没法让它工作。我可以看到console.log(“On auth”);在控制台中,但在那之后什么都不会发生。就好像它停止与该功能。。。没有可见错误,没有其他控制台消息。有没有人知道会出什么问题 我正在使用LinkedIn的测试公司,它不需要任何管理员权限 我的代码是:Javascript LinkedIn api-获取公司更新,javascript,linkedin,linkedin-api,Javascript,Linkedin,Linkedin Api,我正在尝试使用LinkedIn的api获取公司更新。不知怎么的,我没法让它工作。我可以看到console.log(“On auth”);在控制台中,但在那之后什么都不会发生。就好像它停止与该功能。。。没有可见错误,没有其他控制台消息。有没有人知道会出什么问题 我正在使用LinkedIn的测试公司,它不需要任何管理员权限 我的代码是: <head> <script type="text/javascript" src="https://platform.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>
api_密钥:14个字符
onLoad:onLinkedInLoad
授权:正确
函数onLinkedInLoad(){
IN.Event.on(在“auth”中,onLinkedInAuth);
console.log(“On auth”);
}
函数onLinkedInAuth(){
var cpnyID=2414183;//LinkedIn的testDevCo
IN.API.Raw(“/companys/”+cpnyID+“/updates?事件类型=状态更新&start=0&count=10&format=json”)
.结果(显示公司更新);
console.log(“在auth之后”);
}
函数显示公司更新(结果){
var div=document.getElementById(“显示更新”);
var el=“”;
var resValues=result.values;
for(resValues中的var i){
var share=resValues[i].updateContent.companyStatusUpdate.share;
var isContent=share.content;
var isTitled=isContent,
isLinked=isContent,
isDescription=isContent,
isThumbnail=内容不完整;
如果(标题为){
var title=isContent.title;
}否则{
var title=“新闻标题”;
}
如果(已链接){
var link=isContent.shortenedUrl;
}否则{
var link=“#”;
}
if(描述){
var description=isContent.description;
}否则{
var description=“无描述”;
}
如果(isThumbnailz){
var thumbnailUrl=isContent.thumbnailUrl;
}否则{
var thumbnailUrl=”http://placehold.it/60x60";
}
如果(共享){
var content=“
”+说明;
el+=“- ”+内容+“
”;
}
console.log(共享);
}
el+=“
”;
div.innerHTML=el;
}
我最终将此添加到了头中-将onLinkedInAuth
添加到onLoad:
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: 14characters
onLoad: onLinkedInLoad, onLinkedInAuth
authorize: true
</script>
api_密钥:14个字符
onLoad:onLinkedInLoad,onLinkedInAuth
授权:正确
这就成功了。如果在
onLinkedInAuth()的开头放一个console.log()
,它会记录吗?此外,onload应该是-onload**一个逗号分隔的列表**,其中列出了希望SDK在成功加载自身后执行的Javascript函数的名称。
感谢您的响应。不,它在onLinkedInAuth()
的开头没有输出任何内容,因此没有调用onLinkedInAuth()
,因此您的问题是在.Event.on(在“auth”,onLinkedInAuth)中的这一行代码>。没有使用linkedin的api,因此很抱歉,除此之外,我无能为力-您是否尝试过使用不同的eventName
而不是“auth”Ok。我试图将onLoad更改为:onLoad:onLinkedInLoad,onLinkedInAuth,displayCompanyUpdate
,这突然给了我一个错误:“无法读取未定义的属性‘值’”,指向此行:var resValues=result.values
@Craicerjack我通过从onLoad
中删除DisplayCompanyUpdate
解决了这个问题。显然只需要onLinkedInLoad
和onLinkedInAuth
。请留下一个答案,因为你仍然在这条路上帮助我让它工作。谢谢。如何找到公司ID?它是LinkedIn中公司url末尾的数字,例如->ID是3724。