Linkedin分享401未经授权

时间:2013-10-25 17:27:49

标签: c# asp.net linkedin

我从https://developer.linkedin.com/oauth-test-console,i获取来自标题文本框的“oauth_token”访问令牌。

当我尝试使用上述方法时,我得到“远程服务器返回错误:(401)未经授权。” 我正在使用下面的代码。

try
    {

        string xml = "<share>  <comment>Check out the LinkedIn Share API!</comment>  <content>    <title>LinkedIn Developers Documentation On Using the Share API</title>";
        xml += "<description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>";
        xml += "<submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>";
        xml += " <submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url>  </content>  <visibility>";
        xml += " <code>anyone</code> </visibility></share>";
        string accessCodeUri = "http://api.linkedin.com/v1/people/~/shares?oauth2_access_token=generated token"; // this is session value which you get on authorization success return by linkedin
        WebRequest request = WebRequest.Create(accessCodeUri);
        request.Method = "POST";
        request.ContentType = "application/xml";
        request.ContentLength = xml.Length;
        StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
        requestWriter.Write(xml);
        requestWriter.Close();
        WebResponse webResponse = request.GetResponse();
        //success
    }
    catch (WebException exc)
    {
    }

即使我尝试过使用https://www.linkedin.com/uas/oauth2/authorization?response_type=code &安培; CLIENT_ID = YOUR_API_KEY &安培;范围= r_basicprofile%20r_emailaddress &安培;状态= STATE &安培; REDIRECT_URI = YOUR_REDIRECT_URI 从这个URL我已经采取“代码(查询字符串)”,我已经尝试过。但是得到相同的错误

1 个答案:

答案 0 :(得分:1)

OAuth测试控制台仅限OAuth 1.0。 oauth2_access_token是OAuth 2.0,它们不兼容。

无论如何,控制台的oauth_token是“访问代码”,应该发布到https://api.linkedin.com/uas/oauth/accessToken api。作为对您的accessToken请求的回复,您的accessToken将位于“oauth_token”字段和oauth_token_secret中。

然后你可以创建一个共享。控制台显示的标题应添加到您的请求中,以接收access_token

请参阅文件https://developer.linkedin.com/documents/getting-oauth-tokenhttps://developer.linkedin.com/documents/making-api-call-oauth-token调用API