我试图通过oAuth获取LinkedIn API的RequestToken。我已经尝试了很多东西并阅读了我能找到的与该主题相关的所有文档,并且巧妙地尝试了我能想到的所有解决方案。
我使用的代码如下:
public Dictionary<string, string> GetAccessToken()
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://api.linkedin.com/uas/oauth/requestToken");
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
string header = string.Format(@"OAuth oauth_nonce=""{0}"", oauth_signature_method=""{1}"", oauth_timestamp=""{2}"", oauth_consumer_key=""{3}"", oauth_signature=""{4}"", oauth_version=""{5}""",
HttpUtility.UrlEncode(GenerateNonce()), HttpUtility.UrlEncode(getSignatureMethod()), HttpUtility.UrlEncode(GenerateTimeStamp()), HttpUtility.UrlEncode(getClientID()), HttpUtility.UrlEncode(getClientSecret()), HttpUtility.UrlEncode(getVersion()));
request.Headers.Add("Authorization", header);
request.Method = "POST";
HRArtis_Security.MyProxy HRProxy = new HRArtis_Security.MyProxy();
request.Proxy = HRProxy;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string retVal = reader.ReadToEnd();
foreach (string token in retVal.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
return tokens;
}
然后我对该URL执行POST。
尝试使用行HttpWebResponse response = request.GetResponse() as HttpWebResponse
我尝试的另一个选项是将这些参数添加到标题中,但没有结果。
我错过了什么或是个白痴?