Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# - Object reference not set to an instance

I'm trying to get tweets from twitter

But I get an error

Object reference not set to an instance

Code:

    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;
                    }
                  }
                }

this is what the code terminated by Object reference not set to an instance

Getting id as 38811592704 but the below line getting null value

var twt = service.GetTweet(new GetTweetOptions { Id = id });

   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();
    }

Any ideas? Thanks in advance.

like image 465
user2500094 Avatar asked Nov 01 '22 16:11

user2500094


1 Answers

The only thing that ca cause you problem here is your class constructor

new GetTweetOptions

is giving you exception. Go to the constructor of this class and see what is creating error

like image 128
Ehsan Avatar answered Nov 12 '22 21:11

Ehsan