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

Commented Unassigned: Error on UserStream.Start() when user is following somebody [1919]

$
0
0
I've been testing the tweetinvi API with a test account on twitter.

Initially, everything worked great. However, when I followed another user (between executions of my app) and attempted to start the stream, the stream immediately stopped with an InvalidCastException.

Stack trace:
System.InvalidCastException: Specified cast is not valid.
at Streaminvi.UserStream.UserFriends(Object friends) in c:\Users\timart\Documents\My Box Files\Development\Tweetinvi\Streaminvi\UserStream.cs:line 340
at Streaminvi.UserStream.<>c__DisplayClassc.<StartStream>b__b(String x) in c:\Users\timart\Documents\My Box Files\Development\Tweetinvi\Streaminvi\UserStream.cs:line 149
at Streaminvi.Helpers.StreamResultGenerator.StartStream(Func`2 processObject, Func`1 generateWebRequest) in c:\Users\timart\Documents\My Box Files\Development\Tweetinvi\Streaminvi\Helpers\StreamResultGenerator.cs:line 134

When I unfollow the user, the stream works just fine.
Comments: ** Comment from web user: _kurt **

Downloaded the latest, didn't solve my problem. I figured out why I was getting this error. Turns out that inside UserStream.cs at protected virtual void UserFriends(object friends), we create our list of friend ids:

```
_tokenUser.FriendIds = new List<long>();
foreach (var followingId in followingIds)
{
_tokenUser.FriendIds.Add((int)followingId);
}
```
Turns out that one of my friends has an id value of 2190875869
But 2190875869 > 2147483647 (int.MaxValue) - which explains the InvalidCastException

The fix is simple, convert to int64:

```
_tokenUser.FriendIds = new List<long>();
foreach (var followingId in followingIds)
{
_tokenUser.FriendIds.Add(Convert.ToInt64(followingId));
}
```

Awesome API though, really appreciate the hard work.

_kurt


Viewing all articles
Browse latest Browse all 4126

Trending Articles



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