远程服务器返回错误:(403)Forbidden - LinkedIn Share

时间:2016-02-04 09:16:45

标签: c# asp.net-mvc linkedin

我正在使用以下代码使用asp.net MVC分享发布到LinkedIn。

public string Share(string linkedInResponseFromServer)
{
    JObject jobject = JObject.Parse(linkedInResponseFromServer);
    JToken accessCode = jobject["access_token"];

    string requestUrl = "https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=" + accessCode;
    WebRequest request = WebRequest.Create(requestUrl);

    request.UseDefaultCredentials = true;
    request.Method = "POST";
    request.ContentType = "application/json";            

    using (var stream = new StreamWriter(request.GetRequestStream()))
    {
        var shareMsg =
            new
            {
                comment =
                    "BIG Code is site where you can get code for sharing to various social sites. "
                    + "Currently, the site shows how you can use linkedIn OAuth2 related api usage. "
                    + "Add the site to your faviorite and keep checking for the updates.",
                content =
                    new
                    {
                        title = "BIG Code - Reference for Social Api code in C#",
                        submitted_url = "http://www.bigcode.net",
                        submitted_image_url =
                            "http://2.bp.blogspot.com/-8r_lWT_32lQ/TxrQW12ngPI/AAAAAAAAI70/ifMF4Z16M-Y/s1600/SQL+Server+session+state.png",
                        description = string.Empty
                    },
                visibility = new { code = "anyone" }
            };

        string json = new JavaScriptSerializer().Serialize(shareMsg);
        stream.Write(json);
        stream.Flush();
        stream.Close();
    }

    WebResponse webResponse = request.GetResponse();
    Stream dataStream = webResponse.GetResponseStream();
    var reader = new StreamReader(dataStream);
    string response = reader.ReadToEnd();
    return response;
}

但它给出了以下错误        WebResponse webResponse = request.GetResponse();线。

错误是"其他信息:远程服务器返回错误:(403)禁止"

如何解决此问题。

0 个答案:

没有答案