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();
开发者_StackOverflow 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
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.
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);
精彩评论