1

this is the my first question in SO witch I use alot btw :). this is the problem/challenge:

I'm building a service where the user can select a number of his facebook and twitter friends, he will then get a combined list of tweets and statuses of those. Facebook was no problem using batch request was very useful and easy to implement. Im trying to get the same result from twitter, but this seems harder then it seem.

I have a list of all my friends (name and user_id), I want to select a few of those friends and retrieve their tweets. Im using linqToTwitter, a direct HTTP request is also welcome :).

this is what im trying:

var tweetsResult =
                (from search in twitterCtx.Search
                  where search.Type == SearchType.Search &&
                    search.Query == "from:cinek24 OR from:blaba"
                  select search).Single();

this works with public users like cnn but not private friends, and yes i have valid tokens.

MQoder
  • 712
  • 8
  • 21

2 Answers2

3

Here's how you would do the users look-up in LINQ to Twitter:

        var users =
            (from user in twitterCtx.User
             where user.Type == UserType.Lookup &&
                   user.ScreenName == "cinek24,blaba"
             select user)
            .ToList();

        users.ForEach(user => Console.WriteLine("Name: " + user.Name));

More info here:

http://linqtotwitter.codeplex.com/wikipage?title=Querying%20User%20Details&referringTitle=Getting%20User%20Information

Once you have the users, then you'll have to query each of them for their tweets because the user lookup will only return their last tweet, like this:

        var statusTweets =
            from tweet in twitterCtx.Status
            where tweet.Type == StatusType.User
                  && tweet.ScreenName == "cinek24"
                  && tweet.Count == 40
            select tweet;

        tweets.ToList().ForEach(
            tweet => Console.WriteLine(
                "Name: {0}, Tweet: {1}\n",
                tweet.User.Name, tweet.Text));

More info on that query here:

http://linqtotwitter.codeplex.com/wikipage?title=Querying%20the%20User%20Timeline&referringTitle=Making%20Status%20Queries%20and%20Calls

Joe

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • Thanx for the answer, i guess there is no way that this could be done in one request like facebook. Lets hop Twitter will provide this in the future. – MQoder Jun 27 '12 at 20:06
  • I already implemented a method witch retreives a N number of tweets of a user, now i loop through that method using different userIds. this takes about 800ms per request witch is a lot of time. I set your answer as accepted because i think there is no way doing it in one request. – MQoder Jun 27 '12 at 20:19
  • MQoder, that sounds like a Status User query: var statusTweets = from tweet in twitterCtx.Status where tweet.Type == StatusType.User && tweet.ScreenName == "JoeMayo" && tweet.Count == 200 select tweet; – Joe Mayo Jun 28 '12 at 02:58
2

This is the API call you need - users/lookup

https://api.twitter.com/1/users/lookup.json?screen_name=twitterapi,twitter,edent,MQoder&include_entities=true

This will return the most recent tweet from all those screen_names. You can also use user_ids if you prefer.

Terence Eden
  • 14,034
  • 3
  • 48
  • 89