0

I am working on the Linkedin Api. In my OAuthLinkedin.cs, I have the following:

        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

WebResponseGet(HttpWebRequest webRequest) is where it fails. Status: System.Net.WebExceptionStatus.Protocol error The remote server returned an error: (401) Unauthorized.

It is able to get a token secret after requesting permission to access linkedin. but I am not sure abt this unauthorized error. is it some permission issue. where do I check this

Thanks Sun

1
  • hopefully you anonymized your token secrets in this post ;-) Commented Sep 26, 2011 at 21:42

2 Answers 2

2

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

  • 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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.