简体   繁体   中英

Not getting Profile Pic and Email address from linkedin api in MVc4

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.

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

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