Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Edited Unassigned: Null Object Reference [2276]

$
0
0
whenever i try to get follower or friends of any user, the API gives me exception of "Null Object Reference".

List<string> total = new List<string>();

List<Tuple<int, string>> popular = new List<Tuple<int, string>>();
total.Add("");//there wiil be user 1 in list
total.Add("");//there wiil be user 2 in list
total.Add("");//there wiil be user 3 in list
total.Add("");//there wiil be user 4 in list
total.Add("");//there wiil be user 5 in list

for (int i = total.Count()- 1; i >=0; i--)
{
List<Tuple<int, string>> total1 = new List<Tuple<int, string>>();
string name = total[i];
var user = Tweetinvi.User.GetUserFromScreenName(name);
var followers = user.GetFollowers();
int a = user.FollowersCount;
total1.Add(new Tuple<int, string>(a, name));
var friends = user.GetFriends();
foreach (var follower in followers)
{
var nuser = Tweetinvi.User.GetUserFromScreenName(follower.ScreenName);
total1.Add(new Tuple<int, string>(nuser.FollowersCount,follower.ScreenName));

}
foreach (var friend in friends)
{
var nuser = Tweetinvi.User.GetUserFromScreenName(friend.ScreenName);
total1.Add(new Tuple<int, string>(nuser.FollowersCount,friend.ScreenName));
}

total1.Sort();
popular.Add(new Tuple<int,string>(total1[total1.Count()-1].Item1,total1[total1.Count()-1].Item2));
}

for (int i = 0; i < popular.Count(); i++)
{
Label1.Text += popular[i].Item1 + " " + popular[i].Item2 + "<br/>";
}

}

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>