LinkedIn full profile details using DotNetOpenAuth in MVC4

前端 未结 1 1647
情深已故
情深已故 2021-02-09 05:33

My MVC4 application allows login using LinkedIn account. I want to pull all details that are avaible from linkedIn of the logged in User. Currently i have done the following.

相关标签:
1条回答
  • 2021-02-09 06:07

    The response of your request from LinkedIn will be a xml file. The format and fields are mentioned in LinkedIn Profile Fields

    For getting email field, you need to modify your request token url as

    RequestTokenEndpoint = new MessageReceivingEndpoint("https://api.linkedin.com/uas/oauth/requestToken?scope=r_fullprofile+r_emailaddress", HttpDeliveryMethods.PostRequest),

    You can get the fields as required in the following code

     XDocument document = LoadXDocumentFromStream(responseStream); 
    

    Eg : For getting the first name field from the xml file,

    var firstName = document.Root.Element("first-name").Value;
    

    Fields like languages, positions, skills etc will be returned as structured objects as part of the profile.

    Eg : Language field.

        var Lang = document.Root.Element("languages");                        
        var languages = new List<string>();
        if (Lang != null)
        {
         foreach (var l in Lang.Elements())
            {
              if (l.Element("language") != null && l.Element("language").Element("name") != null)
              {
                languages.Add(l.Element("language").Element("name").Value);
               }
             }
          }
    

    Then you can add fields to "extraData" which can be accessed in the controller.

     extraData.Add("firstName", firstName);
     extraData.Add("languages", lang);
    
    0 讨论(0)
提交回复
热议问题