C# Twitter API不支持证书密钥算法
我们正在从twitter时间线中提取最新的推文,但我看到一个错误“证书密钥算法不受支持”,并显示一条消息“基础连接已关闭:接收时发生意外错误”。这只发生在后台和实时服务器上,而不是在我的开发机器上 该页返回一个标准服务器错误。下面是我们用屏幕名调用的类。我们已经仔细检查了oAuth使用者密钥和密码是否正确C# Twitter API不支持证书密钥算法,c#,twitter,twitter-oauth,httpwebresponse,x509certificate2,C#,Twitter,Twitter Oauth,Httpwebresponse,X509certificate2,我们正在从twitter时间线中提取最新的推文,但我看到一个错误“证书密钥算法不受支持”,并显示一条消息“基础连接已关闭:接收时发生意外错误”。这只发生在后台和实时服务器上,而不是在我的开发机器上 该页返回一个标准服务器错误。下面是我们用屏幕名调用的类。我们已经仔细检查了oAuth使用者密钥和密码是否正确 public static List<Tweet> GetTimeline(string screenName) { try { // Do the
public static List<Tweet> GetTimeline(string screenName)
{
try
{
// Do the Authenticate
var authHeaderFormat = "Basic {0}";
var authHeader = string.Format(authHeaderFormat,
Convert.ToBase64String(Encoding.UTF8.GetBytes(Uri.EscapeDataString(oAuthConsumerKey) + ":" + Uri.EscapeDataString((oAuthConsumerSecret)))
));
var postBody = "grant_type=client_credentials";
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(oAuthUrl);
authRequest.Headers.Add("Authorization", authHeader);
authRequest.Method = "POST";
authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
authRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (Stream stream = authRequest.GetRequestStream())
{
byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
authRequest.Headers.Add("Accept-Encoding", "gzip");
WebResponse authResponse = authRequest.GetResponse();
// deserialize into an object
TwitAuthenticateResponse twitAuthResponse;
using (authResponse)
{
using (var reader = new StreamReader(authResponse.GetResponseStream()))
{
JavaScriptSerializer js = new JavaScriptSerializer();
var objectText = reader.ReadToEnd();
twitAuthResponse = JsonConvert.DeserializeObject<TwitAuthenticateResponse>(objectText);
}
}
// Do the timeline
var timelineFormat =
"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={0}&include_rts=1&exclude_replies=1&count=20";
var timelineUrl = string.Format(timelineFormat, screenName);
HttpWebRequest timeLineRequest = (HttpWebRequest)WebRequest.Create(timelineUrl);
var timelineHeaderFormat = "{0} {1}";
timeLineRequest.Headers.Add("Authorization", string.Format(timelineHeaderFormat, twitAuthResponse.token_type, twitAuthResponse.access_token));
timeLineRequest.Method = "Get";
WebResponse timeLineResponse = timeLineRequest.GetResponse();
var timeLineJson = string.Empty;
using (authResponse)
{
using (var reader = new StreamReader(timeLineResponse.GetResponseStream()))
{
timeLineJson = reader.ReadToEnd();
}
}
JArray tweets = JArray.Parse(timeLineJson);
return (from t in tweets
select new Tweet
{
date = DateTime.ParseExact((string)t["created_at"], "ddd MMM dd HH:mm:ss +ffff yyyy", new System.Globalization.CultureInfo("en-US")),
link = t["entities"]["urls"].Count() > 0 ? (string)t["entities"]["urls"][0]["url"] : "",
tweet = LinkUpTweet((string)t["text"]),
author = (string)t["user"]["name"],
screenname = (string)t["user"]["screen_name"],
tweetLink = string.Format(@"https://twitter.com/{0}/status/{1}", screenName, (string)t["id_str"])
}).ToList();
}
catch (Exception ex)
{
// Send Email Error
return new List<Tweet>();
}
有什么建议吗
谢谢 您是否检查了发生故障的服务器上的时间?如果服务器的时间与twitter服务器上的时间相差几分钟,您有时会看到请求失败。确保所有内容都与NTP同步,看看是否有效。我们修复了它-我认为我们永远也不会发现它的原因,但我们完成了清除为解决方案编译的DLL的工作,并在服务器上的新文件夹中重新构建了它,并且工作正常。我猜项目中某个地方的一行代码破坏了它,但永远不会知道不幸的是什么
我们确实检查了服务器上的时间,但那里似乎一切正常。简单问题:您是否尝试在登台和Prod服务器主机上的web浏览器中访问要发布到的URL?我之所以这么问,是因为您的问题听起来像是低级证书握手错误,而不是与oAuth/Basic身份验证握手有关。这篇文章建议system.Diagnostics部分可能导致此问题,我在服务器上检查过,只看到一个通用的内部服务器错误。我的web.config中也没有system.diagnostics部分,如果将其添加到中,则不会产生任何差异。我也读过那篇文章,但毫无乐趣。
<system.diagnostics>
<switches>
<add name="System.Net" value="0"/>
</switches>
</system.diagnostics>