社交媒体共享的事件处理(linkedin和g plus)

时间:2018-10-22 13:05:44

标签: jquery linkedin linkedin-api

我在我的应用程序中使用linkedIn。当我共享应用程序的URL时,我还想处理一个事件(函数),该事件将记录点击次数并保存在数据库中。共享我的网址时,在动态处理事件时遇到问题。

这是html

<div class="linkedinShare ci-aling" linkedin data-url='{{url}}' data-title='{{title}}' data-summary="{{text}}" data-shares='linkedinshares'>{{linkedinshares}}</div>

这是无法使用的linkedin脚本功能

$.getScript('http://platform.linkedin.com/in.js', function () {
    debugger
    function handleLinkedInEvent(event) {
        debugger
        if (event) {
            EventService.UpdateEventAudit($scope.event_id, "LinkedIn", GetUrlReferrer());
        }
    }
    IN.Event.on(IN, 'systemReady', handleLinkedInEvent);
});

UpdateEventAudit是我在与社交媒体共享url并将日志保存到数据库时必须调用的函数。

有人知道问题在哪里吗,为什么不调用UpdateEventAudit函数?

1 个答案:

答案 0 :(得分:0)

如果我正确理解了这一点,那么当用户通过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(StackOverflowDemo.updateShareCount)
      .error(function(errorMessage){
        StackOverflowDemo.logOutput('error occurred');
        console.log(errorMessage);
      });
    };

    document.body.appendChild(shareLink);

  });

  var StackOverflowDemo = {
    updateShareCount: function(result){
      var existingCount = parseInt( document.getElementById('count').value );
      existingCount = isNaN(existingCount) ? 0 : existingCount;
      document.getElementById('count').value =  existingCount + 1;
      StackOverflowDemo.logOutput( 'updated count' );
      StackOverflowDemo.logOutput( 'Total Shares = ' +  document.getElementById('count').value );
      StackOverflowDemo.logOutput( 'View Share here ' + result.updateUrl );
    },
    logOutput: function(text){
      document.getElementById('output').value +=  text + '\n';
    }
  }