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

Do you receive the Exception 429 in the ExceptionHandler or is it raised from an operation (meaning that you need to use try/catch to manage the exception)?

The 429 WebException is an exception sent by Twitter that let you know that you've reached the rate limits.
In Tweetinvi you can get your rate limits using the RateLimit static class.

``` c#
var rateLimits = RateLimit.GetCurrentCredentialsRateLimits();
```

Please let me know how you receive the 429 exception as asked above.
Regards,
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>