使用LINQ to Twitter进行身份验证后获取用户信息

时间:2012-12-07 21:33:40

标签: c# authentication userinfo linq-to-twitter

我希望在使用Twitter进行身份验证后检索用户信息。为此我正在使用LINQ to Twitter库。可以使用此代码:

 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();

但这是将ScreenName设置为MRade90的硬编码。是否可以为当前经过身份验证的用户执行相同的操作?

3 个答案:

答案 0 :(得分:2)

我找到了。可以从WinRtAuthorizer类的Credentials属性访问当前用户凭据。例如,您可以像这里一样使用ScreenName:

string screenName = auth.Credentials.ScreenName;

答案 1 :(得分:0)

我正在使用

var users =
                                         (来自twitterCtx1.User中的用户                                           user.Type == UserType.Lookup&&                                             //user.UserID == list1                                             list1.Contains(user.UserID)                                              选择用户)                                             .ToList();

但是,我无法提取用户ID并正常工作。我可能会出错的任何输入。

由于

答案 2 :(得分:0)

这就是我的做法,

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();