使用api在linkedin上共享的步骤

时间:2016-03-09 13:39:15

标签: java linkedin

我很难在linkedin上分享。我试图通过其在LinkedIn API上发布LinkedIn分享更新。有没有人可以告诉我如何在链接的共享更新上发布并给我步骤来管理它。

2 个答案:

答案 0 :(得分:0)

首先,您必须登录LinkedIn开发者并创建应用以获取特定于您的应用的API代码:Login Here

然后,您学习的最快方式是查看一些示例。以下是您尝试编码的工作版本:http://datopstech.com/linkedin-share-tool/

为了让自己运行此代码,您唯一需要更改的是HTML代码段中的API_Key。

可以找到here的来源,或者我复制并粘贴以下相关部分以供参考:

$(document).ready(function(){

$("#submit_button").click(function organizeinput(){
	if (IN.User.isAuthorized() == true){
var values = new Array();
//comment, title, description, image-content, image-url
// Get the parameters as an array
values = $(":input").serializeArray();
// Find and replace `content` if there
var countinput=0;
for (index = 0; index < values.length; ++index) 
	{
	    if (values[index].name == "comment" && values[index].value != "") 
	    {
	        var comment;
	        comment = values[index].value;
	        countinput=countinput+1;
	    }
	    if (values[index].name == "title" && values[index].value != "") 
	    {
	        var title;
	        title = values[index].value;
	        countinput=countinput+1;
	    }
	    if (values[index].name == "description" && values[index].value != "") 
	    {
	       var description;
	       description = values[index].value;
	       countinput=countinput+1;
	    }
	    if (values[index].name == "image-content" && values[index].value != "") 
	    {
	        var imagecontent;
	        imagecontent = values[index].value;
	        countinput=countinput+1;
	    }
	    if (values[index].name == "image-url" && values[index].value != "") 
	    {
	        var imageurl;
	        imageurl = values[index].value;
	        countinput=countinput+1;
	    }
	}	

if (countinput == 5){
var postcontent = new Array();
postcontent = {"comment": comment, "content": {"title": title,"description": description,"submitted-url": imagecontent,"submitted-image-url": imageurl},"visibility": {"code": "anyone"} };
postcontent = JSON.stringify(postcontent);

shareContent(postcontent);
}
else alert("All the fields are required.");
}
else alert("You have to login to linkedin before you can post content.");
});


function onLinkedInLoad() {
	  IN.Event.on(IN, "auth", organizeinput);
	}

  // Handle the successful return from the API call
  function onSuccess(data) {
    console.log(data);
    alert("Post Successful!");
  }

  // Handle an error response from the API call
  function onError(error) {
    console.log(error);
    alert("Oh no, something went wrong. Check the console for an error log.");
  }

  // Use the API call wrapper to share content on LinkedIn
  function shareContent(pcontent) {

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


//function executepost (pcontent)
//{
	//$.post("https://api.linkedin.com/v1/people/~/shares?format=json", postcontent, function() {return null;});
	// Setup an event listener to make an API call once auth is complete
	
	
//}

});

/*
$.ajax({
    url: "https://api.linkedin.com/v1/people/~/shares?format=json",
    type: 'post',
    data: postcontent,
    headers: {
    	'Content-Type': 'application/json',
		'x-li-format': 'json'
    },
    dataType: 'json',
    success: function (data) {
        console.info(data);
    }
});*/

// Convert to URL-encoded string
//values = jQuery.param(values);
/*
if (crflag ==1)
{
	$.post("index.php", values, function(response) {processdata(response); return response;});
}
else
{
	alert("Sorry, looks like we are missing some input");
}
//$.post("db_insert.php", $(":input").serializeArray(), function(tabledata){$("#result").html(tabledata);});
*/
Status API Training Shop Blog About Pricing
© 2016 GitHub, Inc. Terms Privacy Security Contact Help
<DOCTYPE html>
<html lang="en">
<head>
  <title>Linkedin Share Link With Image, Choose Picture for Hyperlink Thumbnail, JSON Post Developer, Web Tool, Without Meta Property og: tag Online</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- add jQuery -->
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  <!-- add bootstrap -->
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

  <!-- user typed js for form -->
  <script src="postscript.js"></script>
  
   <!-- initialize LinkedIn JS SDK -->
  <script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key: //YOUR API KEY HERE
  authorize: true
  //onLoad: onLinkedInLoad
  </script>
</head>
<body>
	
<div class="wrap"> 
<h1 align="center">Create An Advanced LinkedIn Post</h1>
<p align="center">Configure a share post for Linkedin. First, authorize through LinkedIn by logging in.</br> Then, fill out all of the fields below and click submit to share the content.</br></br><script type="in/Login"></script></p> <br><br>

<div class="col-md-4"><!--quick spacer :)--></div>
	<div class="col-md-5">
		<form name="post_content" action="" method="post">
			<label for="comment">Comment: </label>
			<input type="text" class="form-control" name="comment" placeholder="Comment" required></input><br>
			<label for="title">Title: </label>
			<input type="text" class="form-control" name="title" placeholder="Title" required></input><br>
			<label for="description">Description: </label>
			<input type="text" class="form-control" name="description" placeholder="Description" required></input><br>
			<label for="image-content">Link to Content: </label>
			<input type="text" class="form-control" name="image-content" placeholder="http://example.com/content" required></input><br>
			<label for="image-location">Image Location: </label>
			<input type="text" class="form-control" name="image-url" placeholder="http://example.com/images/example.jpg" required></input><br><br>
			<input type="button" id="submit_button" value="Submit" class="btn btn-default"></input>
			
		</form>
	</div>
</div>
</div>

<div id="VINoutput"></div>
</body>
</html>

答案 1 :(得分:0)

只需使用这样的网址...

https://www.linkedin.com/sharing/share-offsite/?url={url}

来源: Microsoft LinkedIn Share URL Documentation

例如,这对我有用:

https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/

演示: