javascript - 如何将帖子分享到 linkedin

标签 javascript php json share linkedin

我的任务是分享一个从页面链接的帖子。我已经浏览了文档中的链接,但我不明白该怎么做。 我已经用谷歌搜索了好几天,但我没有得到一个清晰的想法。

任何人都可以清楚地解释如何分享到 linkedin。我不想分享整个页面,只想分享特定的帖子。

这是我从网上得到的代码,但我不知道这段代码发生了什么。

<html>
<head>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key: xxxxxxxxx
  authorize: true
  onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
      // Setup an event listener to make an API call once auth is complete
    function onLinkedInLoad() {
      IN.Event.on(IN, "auth", shareContent);
    }
    // Handle the successful return from the API call
    function onSuccess(data) {
      console.log(data);
    }
      // Handle an error response from the API call
    function onError(error) {
      console.log(error);
    }

   // Use the API call wrapper to share content on LinkedIn
    function shareContent() {
            // Build the JSON payload containing the content to be shared
      var payload = {
            Content-Type: application/json
            x-li-format: json
            "comment": "Check out developer.linkedin.com!",
            "content": {
                "title": "LinkedIn Developers Resources",
                "description": "Leverage LinkedIn's APIs to maximize engagement",
                "submitted-url": "https://developer.linkedin.com",  
                "submitted-image-url": "https://example.com/logo.png"
            },
           "visibility": {
               "code": "anyone"
           }  
      };

      IN.API.Raw("/people/~/shares?format=json")
     .method("POST")
     .body(JSON.stringify(payload))
     .result(onSuccess)
     .error(onError);
  }

</script>
</head>
<body>
    <script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share"></script>
</body>
</html>

除了代码,我还需要任何其他文件吗?

我在 codeigniter 工作。

请帮忙。

提前致谢。

最佳答案

我读了你的 javascript 代码,它实际上在做你想做的事,但我认为你应该用 php 或 nodejs 来做这件事,比如后端语言。

要执行此操作以及更多操作,您需要使用 Linked in 的 REST API。
所有 REST API 都具有相同的架构,首先您需要验证您的帐户,然后发送请求并获得响应(使用相同的 session )并执行您想要的操作。

编辑:我在 here 中找到了您想要的内容

关于javascript - 如何将帖子分享到 linkedin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34715114/

相关文章:

php - PHP 的 serialize() 函数有什么用?

javascript - 查找 Path2D 的尺寸

javascript - 如何按顺序调用异步 Action 创建者?

javascript - Jquery HTML 方法

javascript - 全屏打开时显示/隐藏按钮

javascript - 在 JavaScript 中重新排序 JSON 列表集合

php - 从 JSON.parse 获取元素

php - 使用基本授权作为中间件 PSR-7 PSR-15

c# - 如何设置 JSON 文件来配置 nlogging

javascript - 如何动态生成表格并对行进行分组