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: linvi **

Hi,

Would you please check your exception handler and get the latest exception.
If you receive an Exception that is 420 or 429 it means that you have reached the rate limit and you cannot access to the GetUser anymore during 15 minutes. This makes the result of the call to be null (and you receive a null user).

Either way, you currently Get the user one time too much. Why do you not do that ?

``` c#
foreach (var follower in followers) // now getting follower of "AmirKingKhan" and their number of //followers
{
total.Add(new Tuple<int, string>(follower.FollowersCount, follower.ScreenName)); //saving the number
}
```
And same thing for friends?

Linvi


Viewing all articles
Browse latest Browse all 4126

Trending Articles



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