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

Commented 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/>";
}

}
Comments: ** Comment from web user: Mudabbir **

We are using API "Tweetinvi" for our project but we are facing a problem using "Tweetinvi". Actually we are trying to make a user network in which we want to get follower and friends of a user and also getting the count(number) of follower of these followers and friends.

Now the problem we are facing is that when we try to get the follower or friends of any user, API give us exception "Null Object Reference".This error occurs at different stages of program not always at same point. Some times API give this error at 1st user, some time it gives error after processing some users correctly and very rare API works correctly. Every time this error occurs at different user.
Below is part of code where we are getting error:

List<Tuple<int, string>> total = newList<Tuple<int, string>>();
string name ="AmirKingKhan"; //username of user

var user = Tweetinvi.User.GetUserFromScreenName(name); // some times we get error here of "Null //object reference"

var followers = user.GetFollowers();

int num = user.FollowersCount;

var friends = user.GetFriends();

total.Add(new Tuple<int, string>(num, name)); // saving the number of

follower and name of user"AmirKingKhan".

foreach (var follower in followers) // now getting follower of "AmirKingKhan" and their number of //followers
{
var nuser = Tweetinvi.User.GetUserFromScreenName(follower.ScreenName); // sometime
//here we get error at 1st iteration of loop and sometime after some iteration
//of loop
if (nuser != null)
{
total.Add(new Tuple<int,string>(nuser.FollowersCount, follower.ScreenName)); //saving the number
//of follower and name of user.

}

}
foreach (var friend in friends) //now getting friends of "AmirKingKhan" and their number of followers
{
var nuser = Tweetinvi.User.GetUserFromScreenName(friend.ScreenName); // sometimehere we get //error"NUll object Reference" at 1st iteration of loop andsometime after some iteration of loop

if (nuser != null)
{ total.Add(new
Tuple<int, string>(nuser.FollowersCount, friend.ScreenName)) //saving the number of follower and name of user.
}
}

All other functions of "Tweetinvi" are working correctly like fetching tweets and timeline of any user etc..But only problem is in getting followers and friends or user.


Viewing all articles
Browse latest Browse all 4126

Trending Articles



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