【问题标题】:Event handling for social media share (linkedin and g plus)社交媒体分享的事件处理(linkedin 和 g plus)
【发布时间】:2019-03-26 13:48:47
【问题描述】:

我在我的应用程序中使用了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 函数?

【问题讨论】:

  • 您永远不会调用您定义的handleLinkedInEvent() 函数。大概您正在使用的共享库引发了一个类似于tweet 的事件,您需要为 G+ 和 LinkedIn 挂钩。
  • @RoryMcCrossan 我该怎么做?
  • 从阅读他们的文档开始
  • @RoryMcCrossan linkedin 文档?
  • 没有您正在使用的库的文档

标签: jquery linkedin linkedin-api


【解决方案1】:

如果我理解正确,您希望能够在用户通过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';
    }
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 2012-08-19
    • 2012-06-05
    • 2014-05-01
    • 2016-07-22
    • 2013-12-18
    相关资源
    最近更新 更多