我遇到了一个问题:当我打开twitter.com时,它会打开,但是当使用Tweetinvi时它不起作用。
因此,我制作了这段代码:
var result = ping.Send("twitter.com");
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
insertlogwithFilename("test ping : 000X" );
}
我设置了代理配置,但ping不起作用。
TweetinviConfig.CurrentThreadSettings.HttpRequestTimeout = 5000000;
TweetinviConfig.CurrentThreadSettings.UploadTimeout = 9000000;
if (noproxy == "0")
{
TweetinviConfig.CurrentThreadSettings.ProxyURL = "http://" + proxyIP + ":" + proxyPort;
}
try
{
Auth.SetUserCredentials(cuskey, secret, accesstoken, useraccessse);
}
catch (Exception exp)
{
insertlogwithFilename("error in authentication :" + exp.Message);
}
try
{
var authenticatedUser = User.GetAuthenticatedUser();
}
catch (Exception exp)
{
insertlogwithFilename("error in user authentication :" + exp.Message);
}
我测试是否连接了与twitter的连接:
public static void testconn()
{
try
{
using (var client = new WebClient())
{
using (var stream = client.OpenRead("https://www.twitter.com"))
{
insertlogwithFilename("test stream : 8666");
}
}
}
catch
{
insertlogwithFilename("test stream : 8766");
}
}
这段代码返回true
public static void testconnping()
{
var ping = new System.Net.NetworkInformation.Ping();
var result = ping.Send("twitter.com");
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
insertlogwithFilename("test ping : 8766" );
//return false;
}
else
{
insertlogwithFilename("test ping : 8666");
//return true;
}
}
此块返回false
答案 0 :(得分:0)
设置TweetinviConfig.CurrentThreadSettings.ProxyURL
时,并不意味着ping.Send
将使用此代理。这意味着Tweetinvi将使用此代理。
如果您想检查Tweetinvi是否实际访问了数据,则需要按照documentation中的说明运行GetAuthenticatedUser
方法。
TweetinviConfig.CurrentThreadSettings.ProxyURL = "http://...";
ExceptionHandler.SwallowWebExceptions = false;
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var authenticatedUser = User.GetAuthenticatedUser();