asp.net mvc4 linkedin integration - 访问发布的股票被拒绝

时间:2012-11-13 11:42:19

标签: c# asp.net-mvc oauth linkedin

我正在为我的asp.net mvc4应用程序开发社交网络集成。

Twitter和Facebook对我来说非常容易,但我严重陷入了LinkedIn。

这是我的代码。

    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);
    }

一切正常,除了最后一件事 - 发布股票 - 尽管我使用所有必要的权限生成令牌,但我获得了发布股票拒绝例外的权限:

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

希望你好伙伴帮帮我。

1 个答案:

答案 0 :(得分:0)

请参阅此处的上一篇文章 - 它描述了如何解决它

https://developer.linkedin.com/forum/permission-scope-request-token-query-not-working?page=1