简体   繁体   English

Linkedin Api远程服务器返回错误:(401)未经授权

[英]Linkedin Api The remote server returned an error: (401) Unauthorized

I am working on the Linkedin Api. 我正在使用Linkedin Api。 In my OAuthLinkedin.cs, I have the following: 在我的OAuthLinkedin.cs中,我有以下内容:

        public string WebResponseGet(HttpWebRequest webRequest)
        {
            StreamReader responseReader = null;
            string responseData = "";

            try
            {
                responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
                responseData = responseReader.ReadToEnd();
            }
            catch
            {
                throw;
            }
            finally
            {
                webRequest.GetResponse().GetResponseStream().Close();
                responseReader.Close();
                responseReader = null;
            }

            return responseData

; ; } My code is able to get a oauthToken, oauthTokenSecret 我的代码能够获得oauthToken,oauthTokenSecret

WebResponseGet(HttpWebRequest webRequest) is where it fails. WebResponseGet(HttpWebRequest webRequest)是它失败的地方。 Status: System.Net.WebExceptionStatus.Protocol error The remote server returned an error: (401) Unauthorized. 状态:System.Net.WebExceptionStatus.Protocol错误远程服务器返回错误:(401)未经授权。

It is able to get a token secret after requesting permission to access linkedin. 在请求访问linkedin的权限后,它可以获得令牌秘密。 but I am not sure abt this unauthorized error. 但我不确定这个未经授权的错误。 is it some permission issue. 是一些许可问题。 where do I check this 我在哪里检查这个

Thanks Sun 谢谢孙

Here are a couple of things that you can try to identify the source of your problem: 以下是您可以尝试确定问题根源的一些事项:

  • Use this OAuth test console and compare the header that you're generating to the one that this tool generates: https://developer.linkedin.com/oauth-test-console If your header is wrong, then LinkedIn will return a 401 status 使用此OAuth测试控制台并将您生成的标头与此工具生成的标头进行比较: https//developer.linkedin.com/oauth-test-console如果您的标头错误,那么LinkedIn将返回401状态

  • If you're posting XML to LinkedIn in your request, then make sure the content type (webRequest.ContentType) is "application/xml" and not "application/x-www-form-urlencoded", otherwise, LinkedIn will return a 401 status. 如果您在请求中将XML发布到LinkedIn,请确保内容类型(webRequest.ContentType)为“application / xml”而不是“application / x-www-form-urlencoded”,否则LinkedIn将返回401状态。

It was happening with me too but i figured it out what i was doing it wrong. 它也发生在我身上,但我弄清楚我做错了什么。

Whenever you create Signature, make Token and TokenSecret empty. 每当您创建签名时,令Token和TokenSecret为空。 it worked for me because it was getting old token and token secret from browser request. 它对我有用,因为它从浏览器请求获得旧的令牌和令牌秘密。

 //Generate Signature
        string sig = this.GenerateSignature(uri,
            this.ConsumerKey,
            this.ConsumerSecret,
            this.Token,
            this.TokenSecret,
            method.ToString(),
            timeStamp,
            nonce,
            out outUrl,
            out querystring);

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

相关问题 错误:远程服务器返回错误:(401)未经授权 - Error :The remote server returned an error: (401) Unauthorized 远程服务器返回错误:(401)未经授权 - The remote server returned an error: (401) Unauthorized 远程服务器未授权返回错误(401) - remote server returned an error (401) unauthorized 远程服务器返回错误:(401)未授权的sharepoint - The remote server returned an error: (401) Unauthorized sharepoint Twitterizer - 远程服务器返回错误:(401)未经授权 - Twitterizer - The remote server returned an error: (401) Unauthorized Web 异常:远程服务器返回错误 (401) 未授权 - Webexception:remote server returned an error (401)unauthorized 远程服务器返回错误:(401)未经授权 - The remote server returned an error: (401) Unauthorized GCM服务器(远程服务器返回错误:(401)未经授权。) - GCM Server ( The remote server returned an error: (401) Unauthorized.) 使用API​​访问令牌oauth 2.0 -error“远程服务器返回错误:(401)未经授权” - using API access token oauth 2.0 -error “The remote server returned an error: (401) Unauthorized” 远程服务器返回错误:(401) Unauthorized when requesting RestApi data - The remote server returned an error: (401) Unauthorized when requesting RestApi data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM