0
votes

I am developing social networks integration for my asp.net mvc4 application.

Twitter and Facebook were very easy for me but I am seriously stuck with LinkedIn.

Here is my code.

    public ActionResult LinkedInTest(string text)
    {
        var client = new RestClient
                         {
                             Authority = "https://api.linkedin.com/uas/oauth",
                             Credentials = LinkedInSocialHelper.GetCredentials()
                         };
        var request = new RestRequest {Path = "requestToken"};
        RestResponse response = client.Request(request);

        token = response.Content.Split('&')[0].Split('=')[1];
        tokenSecret = response.Content.Split('&')[1].Split('=')[1];
        textToPost = text;
        Response.Redirect("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + token + "&scope=r_basicprofile+r_emailaddress+r_network+r_contactinfo+rw_nus");
        return null;
        textToPost = text;
        return RedirectToAction("LinkedInCallback");
    }

    public ActionResult LinkedInCallback()
    {
        verifier = Request["oauth_verifier"];

        var client = new RestClient
                         {
                             Authority = "https://api.linkedin.com/uas/oauth",
                             Credentials = LinkedInSocialHelper.GetCredentials(token, tokenSecret, verifier),
                             Method = WebMethod.Post
                         };
        var request = new RestRequest {Path = "accessToken"};
        RestResponse response = client.Request(request);
        token = response.Content.Split('&')[0].Split('=')[1];
        tokenSecret = response.Content.Split('&')[1].Split('=')[1];
        LinkedInSocialHelper.Post(textToPost, token, tokenSecret);
        return RedirectToAction("Calendar");
    }
    public static void Post(string text, string accessToken, string accessTokenSecret)
    {
        var tokenManager = new TokenManager(ApiKey, ApiSecret);
        tokenManager.ExpireRequestTokenAndStoreNewAccessToken(null, null, accessToken, accessTokenSecret);
        var authorization = new WebOAuthAuthorization(tokenManager, UserToken);
        LinkedInService service = new LinkedInService(authorization);
        //var user = service.GetCurrentUser(ProfileType.Public); - IT IS GIVING ME THE SAME ERROR - Access denied
        service.CreateShare(text, VisibilityCode.ConnectionsOnly);
    }

Everything works fine except last thing - posting shares - I get Access to posting shares denied exception despite the fact that I generate token using all the necessary permissions:

"https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + token + "&scope=r_basicprofile+r_emailaddress+r_network+r_contactinfo+rw_nus"

Hope you good guys help me.

1

1 Answers