领英回调函数
LinkedIn callback function
我想在点击链接的分享按钮后调用一个函数。
<div class="linkedinShare ci-aling" linkedin data-url='{{url}}' data-title='{{title}}' data-summary="{{text}}" data-shares='linkedinshares'>{{linkedinshares}}</div>
这是我尝试调用的脚本,但它只会在页面加载时被调用,而不会在单击共享按钮中的链接时被调用。我希望在单击分享按钮时调用我的函数。
$.getScript('http://platform.linkedin.com/in.js', function () {
debugger
IN.Event.on(IN, 'systemReady', handleLinkedInEvent);
function handleLinkedInEvent(event) {
debugger
if (event) {
EventService.UpdateEventAudit($scope.event_id, "LinkedIn",
GetUrlReferrer());
}
}
});
UpdateEventAudit 是我要调用的函数。有人知道吗?
如果我的理解正确,您希望能够在用户通过 linkedin 分享时跟踪事件...
我试过你的代码,经过一些研发,找到了另一种方法来调用 api...
创建了一支迷你笔,您可以在此处查看https://codepen.io/craigiswayne/pen/Bqqbjz
有关此主题的文档可在此处找到:https://developer.linkedin.com/docs/share-on-linkedin
IN.Event.on(IN, 'systemReady', function() {
var shareLink = document.getElementById('shareLink');
shareLink.onclick = function(){
event.preventDefault();
var params = {
"comment": "Check out developer.linkedin.com! " + this.getAttribute('href'),
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(params))
.result(WhosebugDemo.updateShareCount)
.error(function(errorMessage){
WhosebugDemo.logOutput('error occurred');
console.log(errorMessage);
});
};
document.body.appendChild(shareLink);
});
var WhosebugDemo = {
updateShareCount: function(result){
var existingCount = parseInt( document.getElementById('count').value );
existingCount = isNaN(existingCount) ? 0 : existingCount;
document.getElementById('count').value = existingCount + 1;
WhosebugDemo.logOutput( 'updated count' );
WhosebugDemo.logOutput( 'Total Shares = ' + document.getElementById('count').value );
WhosebugDemo.logOutput( 'View Share here ' + result.updateUrl );
},
logOutput: function(text){
document.getElementById('output').value += text + '\n';
}
}
我想在点击链接的分享按钮后调用一个函数。
<div class="linkedinShare ci-aling" linkedin data-url='{{url}}' data-title='{{title}}' data-summary="{{text}}" data-shares='linkedinshares'>{{linkedinshares}}</div>
这是我尝试调用的脚本,但它只会在页面加载时被调用,而不会在单击共享按钮中的链接时被调用。我希望在单击分享按钮时调用我的函数。
$.getScript('http://platform.linkedin.com/in.js', function () {
debugger
IN.Event.on(IN, 'systemReady', handleLinkedInEvent);
function handleLinkedInEvent(event) {
debugger
if (event) {
EventService.UpdateEventAudit($scope.event_id, "LinkedIn",
GetUrlReferrer());
}
}
});
UpdateEventAudit 是我要调用的函数。有人知道吗?
如果我的理解正确,您希望能够在用户通过 linkedin 分享时跟踪事件...
我试过你的代码,经过一些研发,找到了另一种方法来调用 api...
创建了一支迷你笔,您可以在此处查看https://codepen.io/craigiswayne/pen/Bqqbjz
有关此主题的文档可在此处找到:https://developer.linkedin.com/docs/share-on-linkedin
IN.Event.on(IN, 'systemReady', function() {
var shareLink = document.getElementById('shareLink');
shareLink.onclick = function(){
event.preventDefault();
var params = {
"comment": "Check out developer.linkedin.com! " + this.getAttribute('href'),
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(params))
.result(WhosebugDemo.updateShareCount)
.error(function(errorMessage){
WhosebugDemo.logOutput('error occurred');
console.log(errorMessage);
});
};
document.body.appendChild(shareLink);
});
var WhosebugDemo = {
updateShareCount: function(result){
var existingCount = parseInt( document.getElementById('count').value );
existingCount = isNaN(existingCount) ? 0 : existingCount;
document.getElementById('count').value = existingCount + 1;
WhosebugDemo.logOutput( 'updated count' );
WhosebugDemo.logOutput( 'Total Shares = ' + document.getElementById('count').value );
WhosebugDemo.logOutput( 'View Share here ' + result.updateUrl );
},
logOutput: function(text){
document.getElementById('output').value += text + '\n';
}
}