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

Ok,

Your problem comes from the fact that you are performing too much queries and you go beyond the Twitter rate limits.

When you reach a rate-limit, you need to wait until you can perform the operation again.
To do that, you need to calculate the number of operation you do and compare it to the rate limits of Twitter provided by the RateLimit object.

So normally if you set the ExceptionHandler, you will receive a TweetinviException, this exception will contain a WebException with the status code of 420 or 429.

``` C#
ExceptionHandler.SwallowWebExceptions = false;
```

If you continue to have an issue please send me your project (on the contact page) and I will review it for you. Otherwise you can contact me via Skype (just request my contact information on my contact page).

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>