Windows Phone Linq2Twitter - 获取授权用户的屏幕名称,ID和名称?

时间:2013-03-20 05:01:10

标签: c# silverlight windows-phone-7 linq-to-twitter

我是LinQ的菜鸟,并且在Linq2Twitter和Twitter API方面遇到了麻烦。

在成功授权后,我无法理解如何获取授权用户的屏幕名称,ID和名称。

我在线搜索了讨论主题,我从Joe那里得到的唯一建议就是在查询结果时使用异步调用。除了因为某些原因我没有MaterializedAsyncCallback所以我正在使用AsyncCallback。

以下是从授权到尝试获取用户信息的所有步骤:

  1. 使用我的消费者密钥和密码作为凭证创建一个PinAuthorizer

    this.pinAuth = new PinAuthorizer
    {
        Credentials = new InMemoryCredentials
         {
             ConsumerKey = CONSUMER_KEY,
             ConsumerSecret = CONSUMER_SECRET
         },
         UseCompression = true,
         GoToTwitterAuthorization = pageLink =>
         Dispatcher.BeginInvoke(() => {
             WebBrowser.Navigate(new Uri(pageLink + "&force_login=true", UriKind.Absolute));
         })
     };
    
  2. 授权开始

    this.pinAuth.BeginAuthorize(resp => ...
    
  3. 输入pin,从而获得pinAuth.OAuthTwitter中的访问令牌和密码:

    pinAuth.CompleteAuthorize(
        this.pin,
        completeResp => Dispatcher.BeginInvoke(() =>
        { ...
    
  4. 然后,我尝试让用户......使用异步调用,就像Joe Mayo在其他主题中推荐的那样。

    ITwitterAuthorizer auth = pinAuth;
    TwitterContext twitterCtx = new TwitterContext(pinAuth);
    (from user in twitterCtx.User
     where user.UserID != "JoeMayo"
     select user).AsyncCallback(asyncResponse => {
         var response = asyncResponse.ToList();
         User acc = response.FirstOrDefault();
     // Anything in this block is pointless
     // as I never get into this async callback block.
     // But this is where I expect to get the user's info
     // (screen name, name, id, etc.)
    });
    
  5. 我永远不会得到异步响应。 (出于某种原因,我也没有MaterializedAsyncCallback

    如何获取授权用户的屏幕名称,ID和名称?

1 个答案:

答案 0 :(得分:2)

你根本没有发起查询!

(from user in twitterCtx.User
 where user.UserID != "JoeMayo"
 select user).AsyncCallback(users => {
    // result is in users variable
    var user = users.SingleOrDefault();
    if(user != null)
    {
        // use user here.
    }
}).SingleOrDefault();