0

I'm a noob in LinQ and having troubles with Linq2Twitter and Twitter API in general.

I cannot understand how to get an authorized user's screen name, id, and name after a successful authorization.

I searched discussion threads online and the only advice I got from Joe was to use async call when querying for results. Except that I don't have the MaterializedAsyncCallback for some reason so I'm using AsyncCallback instead.

Here are the steps that I take all the way from authorizing to attempting to obtain the user's info:

  1. Create a PinAuthorizer with my consumer key and secret as credentials

    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. Authorize Begin

    this.pinAuth.BeginAuthorize(resp => ...
    
  3. Enter the pin and thus getting access token and secret in pinAuth.OAuthTwitter:

    pinAuth.CompleteAuthorize(
        this.pin,
        completeResp => Dispatcher.BeginInvoke(() =>
        { ...
    
  4. Then, I try to get the user ... with an async call as that's what Joe Mayo recommended in other threads.

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

I never get the async response. (I also do not have MaterializedAsyncCallback for some reason).

How do I get the authorized user's screen name, id, and name?

MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
user1076731
  • 203
  • 3
  • 14

1 Answers1

2

You didn't actually fire the query at all!

(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();
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
  • answer is what you need. More info on same question here: http://linqtotwitter.codeplex.com/discussions/437277 – Joe Mayo Mar 20 '13 at 16:15