简体   繁体   English

Linkedin分享401未经授权

[英]Linkedin share 401 unauthorised

I am taking the access token from https://developer.linkedin.com/oauth-test-console,i am taking " oauth_token" from header text box. 我从https://developer.linkedin.com/oauth-test-console获取访问令牌,我从标题文本框中获取“ oauth_token”。

When I try with the above toke i am getting "The remote server returned an error: (401) Unauthorized." 当我尝试使用上述标记时,我得到“远程服务器返回错误:(401)未经授权。” I am using below code. 我正在使用下面的代码。

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

Even i have tried with https://www.linkedin.com/uas/oauth2/authorization?response_type=code &client_id=YOUR_API_KEY &scope=r_basicprofile%20r_emailaddress &state=STATE &redirect_uri=YOUR_REDIRECT_URI from this URL i have taking the "code(query string)" and i have tried.But getting same error 即使我已经尝试过https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id = YOUR_API_KEY&scope = r_basicprofile%20r_emailaddress&state = STATE&redirect_uri = YOUR_REDIRECT_URI,我也已将“ code(query string )”,而我已经尝试过。但是却收到相同的错误

The OAuth Test console is OAuth 1.0 only. OAuth测试控制台仅是OAuth 1.0。 The oauth2_access_token is OAuth 2.0 and they are incompatible. oauth2_access_token是OAuth 2.0,并且不兼容。

Anyway the Console's oauth_token is the "Access Code" wich should be POSTed to the https://api.linkedin.com/uas/oauth/accessToken api. 无论如何,控制台的oauth_token是“访问代码”,应将其发布到https://api.linkedin.com/uas/oauth/accessToken api。 As a response to your request for an accessToken, your accessToken will be in the "oauth_token" field and an oauth_token_secret. 作为对您对accessToken请求的响应,您的accessToken将在“ oauth_token”字段和一个oauth_token_secret中。

Then you can create a share. 然后,您可以创建一个共享。 The Headers showed by Console should added to your request, to receive the access_token 控制台显示的标题应添加到您的请求中,以接收access_token

Please refer to the document https://developer.linkedin.com/documents/getting-oauth-token And https://developer.linkedin.com/documents/making-api-call-oauth-token to call API 请参阅文档https://developer.linkedin.com/documents/getting-oauth-tokenhttps://developer.linkedin.com/documents/making-api-call-oauth-token来调用API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM