2013-03-20 69 views
0

我是LinQ的noob,遇到Linq2Twitter和Twitter API的问题。Windows Phone Linq2Twitter - 获取授权用户的屏幕名称,ID和名称?

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

我在网上搜索了讨论主题,我从乔那里得到的唯一建议是在查询结果时使用异步调用。除了我没有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. 输入引脚,从而获得访问令牌和秘密pinAuth.OAuthTwitter:

    pinAuth.CompleteAuthorize(
        this.pin, 
        completeResp => Dispatcher.BeginInvoke(() => 
        { ... 
    
  4. 于是,我试图让用户用...一个异步调用的,这就是乔·梅奥在其他线程建议。

    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.) 
    }); 
    

我从来没有得到过异步响应。 (由于某些原因,我也没有MaterializedAsyncCallback)。

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

回答

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

答案是你需要的。有关同一问题的更多信息,请访问:http://linqtotwitter.codeplex.com/discussions/437277 – 2013-03-20 16:15:25