Reputation: 356
I am trying to fetch the followers using Linq To Twitter latest version 3.0.2..But It is not returning back any response either not throw any error. Please suggest
var followers = GetTwitterFollowers
(twitterUserId, auth, maxFollowers);
var foll = followers.ContinueWith(f =>
{
return f.Result;
}).Result;
"GetTwitterFollowers" method defined as:
private static async Task<List<TwitterData>> GetTwitterFollowers(
ulong twitterUserId, SingleUserAuthorizer auth, int? maxFollowers)
{
var follower = maxFollowers ?? 15000;
try
{
var twitterCtx = new TwitterContext(auth);
var followers = await twitterCtx.Friendship
.Where(f => f.Type == FriendshipType.FollowersList
&& f.UserID == twitterUserId.ToString())
.Select(f => new TwitterData()
{
Followers = f.Users.Where(t => !t.Protected).Take(follower).Select(s => s).ToList()
}).SingleOrDefaultAsync();
return GetFollowersList(followers.Followers);
}
catch (Exception ex)
{
return null;
}
}
Upvotes: 1
Views: 184
Reputation: 7513
Get followers from Twitter first:
var friendship =
await
(from friend in twitterCtx.Friendship
where friend.Type == FriendshipType.FollowersList &&
friend.UserID == twitterUserId.ToString()
select friend)
.SingleOrDefaultAsync();
Then you can do your custom projection with an LINQ to Objects query on the results.
Update:
You should await the call to GetTwitterFollowers, like this:
var followers = await GetTwitterFollowersAsync(twitterUserId, auth, maxFollowers);
Then, you don't need the ContinueWith. It isn't working because GetTwitterFollowers returns immediately after hitting the await. The ContinueWith lambda might execute, but there isn't anything keeping the routine from returning and you don't get the result of the lambda execution. It might help to spend a little time looking at async/await to make this easier. Here's something that might help:
http://msdn.microsoft.com/en-us/library/hh191443.aspx
Upvotes: 1