我正在尝试从Twitter获得推文
但我得到一个错误
代码:
public void Call_Tweet_Update()
{
var service = new TwitterService(Consumer_Key, Consumer_Secret);
service.AuthenticateWith(Access_Token, AccessToken_Secret);
var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions { Count = 200 });
string[] twt_id = new string[50];
long id = 0;
int i = 0;
int increment = 0;
string twtid;
string screenname;
foreach (var tweet in tweets)
{
if (tweet.InReplyToStatusId.ToString() != "")
{
if ((tweet.User.ScreenName == "IIPL_LTD") || (tweet.Text.StartsWith("@IIPL_LTD")))
{
string replyid = tweet.InReplyToStatusId.ToString();
while (replyid != "")
{
if (i == 0)
{
twt_id[i] = tweet.Id.ToString();
}
id = Convert.ToInt64(replyid);
var twt = service.GetTweet(new GetTweetOptions { Id = id });
//twtid = Convert.ToInt64(tweet.Id).ToString();
twtid = Convert.ToInt64(twt.Id).ToString();
//abc = twtid;
i = i + 1;
twt_id[i] = twtid;
replyid = twt.InReplyToStatusId.ToString();
// replyid = tweet.InReplyToStatusId.ToString();
// replyid = "";
increment = increment + 1;
}
}
}
这是由对象引用终止的代码未设置为实例 while (replyid != "")
{
if (i == 0)
{
twt_id[i] = tweet.Id.ToString();
}
id = Convert.ToInt64(replyid);
var twt = service.GetTweet(new GetTweetOptions { Id = id });
twtid = Convert.ToInt64(twt.Id).ToString();
}
有任何想法吗?提前致谢。 最佳答案
导致您出现问题的唯一原因是您的类构造函数
new GetTweetOptions
给你异常(exception)。转到此类的构造函数,看看产生了什么错误