List of user screenname, profilephoto and id of followers

Jun 24, 2013 at 5:08 PM
I have written some code but I don't think trhis is the way to go because I get exceeded rate limit errors. Is there another way to achieve this ? Any help is very much apreciated. I get the error on the bold/italic...

Tis is my currentcode:

Dim credentials As IOAuthCredentials = New InMemoryCredentials
    credentials.ConsumerKey = _twitterConsumerKey
    credentials.ConsumerSecret = _twitterConsumerKeySecret
    credentials.OAuthToken = twitterConnection.OAuthToken
    credentials.AccessToken = twitterConnection.OAuthTokenSecret

    Dim auth As PinAuthorizer = New PinAuthorizer()
    auth.Credentials = credentials
    If auth.IsAuthorized Then
        Dim listofnames As String
        Dim twitterCtx As TwitterContext = New TwitterContext(auth)
        Dim friendList = (From [friend] In twitterCtx.SocialGraph Where [friend].Type = SocialGraphType.Friends AndAlso [friend].UserID = 43953561).SingleOrDefault()
        For Each thisID In friendList.IDs
            Dim friendsid As Integer = thisID
            Dim users = From tweet In twitterCtx.User Where tweet.Type = UserType.Show AndAlso tweet.UserID = friendsid
__ _ Dim user = users.SingleOrDefault()___
            Dim tweetname = user.Name
            Dim profilepic As String = user.ProfileImageUrl
            retVal.Add(New TwitterContact(friendsid, profilepic, tweetname))
        Next
Coordinator
Jun 24, 2013 at 5:43 PM
Hi,

It's the For Each loop on UserType.Show that's causing the problem. Essentially, the user has more friends than what your rate limit is. The recommended approach to this is to use a UserType.Lookup query.

What you would do is continue to do the SocialGraph query like you are. Then do a For Each loop with a UserType.Lookup query, passing in a comma separated list of user ids. Since the limit is 100 user IDs per query, you'll need to add logic to move through the block of 100 or less at a time.

@JoeMayo
Jun 24, 2013 at 6:41 PM
Hi JoeMayo,

Thanx for the advice... However, how would I obtain the user his or hers profile photo? As far as I can read in the documentation the only way to get a profile photo is by tweet.Type = UserType.Show... Any suggestions ?
Coordinator
Jun 24, 2013 at 6:48 PM
Use the ProfileImageUrl or ProfileImageUrlHttps from the User entity returned by the call to UserType.Lookup.

The link, that I gave you in my response above, takes you to the documentation for the query. It includes a return type, which is User. If you click on User, you'll see all of the properties available in User. If the properties in User are not primitive types, you'll see links to those types too.

@JoeMayo
Jun 24, 2013 at 8:22 PM
Hi Joe,

I got to the point where I can create a string with userId's. Then I loop and get profilephoto and screenname... however I would expect to be able to get userId back in the loop... That doesn't seem to work... Any pointers ? Your help is much appreciated and I wil post my sample code as I think it will be of help to many VB people... Please have a look at my code...

Dim twitterCtx As TwitterContext = New TwitterContext(auth)
        Dim friendList = (From [friend] In twitterCtx.SocialGraph Where [friend].Type = SocialGraphType.Friends AndAlso [friend].UserID = 43953561).SingleOrDefault()
        Dim numberoffriends As Integer = friendList.Count

        Dim x As Integer = 0
        Dim liststringusers As String

        For Each thisID In friendList.IDs
            If x = 50 Then Exit For
            Dim friendsid As Integer = thisID
            liststringusers &= thisID
            liststringusers &= ","
            x = x + 1
            Next

        Dim users = (From user In twitterCtx.User Where user.Type = UserType.Lookup AndAlso user.UserID = liststringusers).ToList()
        For Each user In users
__ Dim theuserhisid As String = user.UserID__
            Dim tweetname = user.Name
            Dim profilepic As String = user.ProfileImageUrl
            retVal.Add(New TwitterContact(theuserhisid, profilepic, tweetname))

        Next
Coordinator
Jun 24, 2013 at 8:25 PM
In the User object, I don't modify the id parameters you entered. Rather I populate the Identifier property of Users with that info. Here's more info:

https://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation

@JoeMayo
Jun 25, 2013 at 11:48 AM
Thanx a lot Joe... Got it to work...