【问题标题】:Get user info after authentication using LINQ to Twitter使用 LINQ to Twitter 进行身份验证后获取用户信息
【发布时间】:2012-12-07 21:33:40
【问题描述】:

我想在通过 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。是否可以对当前经过身份验证的用户做同样的事情?

【问题讨论】:

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


    【解决方案1】:

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

    string screenName = auth.Credentials.ScreenName;
    

    【讨论】:

      【解决方案2】:

      我正在使用

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

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

      谢谢

      【讨论】:

      【解决方案3】:

      我就是这样做的,

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-12
        • 1970-01-01
        • 2010-11-13
        • 2018-02-18
        • 1970-01-01
        • 2011-10-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多