简体   繁体   中英

How to handle Invitation API of Linkedin in c# Asp.NET

Can any one guide me how to tackle with Linkedin Invitation API in c# asp.net. I want to send invitation to particular user from my app via this api, but don't find any sufficient information to start it. Can any one give me some example to start with. I have already get list of users from linkedin search api. Now i want to send invitation to those users.

Thanks in advanced. Hope best answer will come out.

Thanks

Finally, it's done. I have successfully implement linkedin invitation api with asp.net c#. I am posting sample code here, for other users who want to implement it.

try
{
     string uid=uniqueid of user,to whom you want to send request.
     // if you get this user bysearch api or 1st connection, then from http-header response, you will find value field. split this value by ':' and store in two variable
     string name=splitvalue1;
     string namevalue=splitvalue2;
     string xml = "<?xml version='1.0' encoding='UTF-8'?><mailbox-item><recipients><recipient><person path=\"/people/id=" + uid + "\" /></recipient></recipients>";
     xml += "<subject>Invitation to Connect</subject>";
     xml += "<body>Please join my professional network on LinkedIn.</body>";
     xml += "<item-content><invitation-request><connect-type>friend</connect-type><authorization><name>" + name + "</name><value>" + namevalue + "</value></authorization></invitation-request></item-content></mailbox-item>";
     string accessCodeUri = "https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=" + Session["accessCode"]; // this is session value which you get on authorization success return by linkedin
     WebRequest request = WebRequest.Create(accessCodeUri);
     request.Method = "POST";
     request.ContentType = "application/xml";
     request.ContentLength = xml.Length;
     StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(),   System.Text.Encoding.ASCII);
     requestWriter.Write(xml);
     requestWriter.Close();
     WebResponse webResponse = request.GetResponse();
     //success
}
catch(WebException exc)
{
}

Hope it helps other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM