0

Here is my code please let me know why am not able to get emailid and profile pic.

public class LinkedInController : Controller
{
    public ActionResult index()
    {
       return AuthenticateToLinkedIn();
    }

    static string token_secret = "";
    public ActionResult AuthenticateToLinkedIn()
    {
        var credentials = new OAuthCredentials
        {
            CallbackUrl = "http://localhost:7326/Linkedin/callback",
            ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
            ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
            Verifier = "123456",
            Type = OAuthType.RequestToken
        };

        var client = new RestClient { Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials };
        var request = new RestRequest { Path = "requestToken" };
        request.AddParameter("scope", "r_emailaddress");

        RestResponse response = client.Request(request);
        string content = response.Conten

        var contents = HttpUtility.ParseQueryString(response.Content)
        var  token = response.Content.Split('&')[0].Split('=')[1];

        token_secret=contents["oauth_token_secret"];              

       Response.Redirect("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + token);
       return null;
    }

    string token = "";
    string verifier = "";
    public ActionResult Callback()
    {    
        token = Request["oauth_token"];
        verifier = Request["oauth_verifier"];
        var credentials = new OAuthCredentials
        {
            ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
            ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
            Token = token,
            TokenSecret = token_secret,
            Verifier = verifier,
            Type = OAuthType.AccessToken,
            ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
            SignatureMethod = OAuthSignatureMethod.HmacSha1,
            Version = "1.0"    
        };

        var client = new RestClient { Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials, Method = WebMethod.Post };

        var request = new RestRequest { Path = "accessToken" };               
        request.AddParameter("scope", "r_emailaddress");            

        RestResponse response = client.Request(request);
        string content = response.Content;     

        var contents = HttpUtility.ParseQueryString(response.Content);

        var accessToken =contents["oauth_token"];
        var accessTokenSecret=contents["oauth_token_secret"];                  

        var people = new LinkedInService(accessToken, accessTokenSecret).GetCurrentUser();               

        String companyName = people.FirstName;
        return Content(companyName);            
    }
}

I am using Hammock and i am getting first name and last name and title and all i have enabled the r_emailadress in LinkedIn Portal but please am not able to get these information.

Vsevolod Goloviznin
  • 12,074
  • 1
  • 49
  • 50
CRESOL
  • 1
  • 1

1 Answers1

0

The only scope you're using is r_emailaddress. To get the pic, I think you need to use r_basicprofile. I can't see a field in the docs called 'emailid', only email-address.

https://developer.linkedin.com/docs/fields/basic-profile

Chris Disley
  • 1,286
  • 17
  • 30
  • i have changed the code to this var request = new RestRequest { Path = "requestToken" }; request.AddParameter("scope", "r_basicprofile"); but still not getting email id and profile pic. – CRESOL Aug 17 '15 at 12:53