3

I want to retrieve user info after authentication with Twitter. For this purpose I'm using LINQ to Twitter library. It's possible to do with this code:

 var usersResponse =
            (from user in context.User
             where user.Type == UserType.Lookup &&
                   user.ScreenName == "MRade90"
             select user).ToList();

        var users =
           (from user in usersResponse
            select new User
            {
                Name = user.Identifier.ScreenName,
                StatusText = user.Status.Text,
                PictureUrl = new Uri(user.ProfileImageUrl)
            }).FirstOrDefault();

But this is hardcoded with ScreenName set to MRade90. Is it possible to do the same thing for currently authenticated user?

Rade Milovic
  • 965
  • 4
  • 13
  • 29

3 Answers3

2

I found it. The current user credentials can be accessed from Credentials property of WinRtAuthorizer class. For example you can use ScreenName like here:

string screenName = auth.Credentials.ScreenName;
Rade Milovic
  • 965
  • 4
  • 13
  • 29
0

I am using

var users =
(from user in twitterCtx1.User where user.Type == UserType.Lookup && //user.UserID == list1 list1.Contains(user.UserID) select user) .ToList();

However, I am not able to extract the user IDs and work . Any inputs where I might be going wrong.

Thanks

Richa Sachdev
  • 2,937
  • 3
  • 17
  • 12
  • I don't think you can do that this way. If you look at the http://linqtotwitter.codeplex.com/SourceControl/latest#LinqToTwitterAg/User/User.cs implementation you will see that it needs user JsonData object in order to get the user information. For that to happend you have to authenticate the user and gather its JsonData (form the OAuth authorizer class I suppose). – Rade Milovic Mar 18 '14 at 11:59
  • This is the implementation of OAuthAuthorizer class: http://linqtotwitter.codeplex.com/SourceControl/latest#LinqToTwitterAg/OAuth/OAuthAuthorizer.cs – Rade Milovic Mar 18 '14 at 12:00
0

This is how I do this,

var auth = new SingleUserAuthorizer
                        {
                            CredentialStore = new SingleUserInMemoryCredentialStore
                            {
                                ConsumerKey = consumerKey,
                                ConsumerSecret = consumerSecret,
                                AccessToken = twitterToken.Token,
                                AccessTokenSecret = twitterToken.TokenSecret                                
                            }
                        };

var twitterCtx = new TwitterContext(auth);

  var acc = (from user in twitterCtx.Account where user.Type == AccountType.VerifyCredentials select user).FirstOrDefault();
Damith
  • 1,982
  • 3
  • 28
  • 42