WPhone - Getting the ScreenName/Name

Mar 20, 2013 at 5:57 AM
Hi there.

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

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

I searched the discussion threads and the only advice I got was to use async call when querying for results.

Here are the steps that I make:
  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));
                })
        };
  1. Authorize Begin
this.pinAuth.BeginAuthorize(resp => ...
  1. Enter the pin and thus getting access token and secret in pinAuth.OAuthTwitter:
pinAuth.CompleteAuthorize(
            this.pin,
            completeResp => Dispatcher.BeginInvoke(() =>
            { ...
  1. 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();
            });
    
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?
Coordinator
Mar 20, 2013 at 5:13 PM
Hi Mike,

There are some demos on the Samples page that you might want to step through and compare to what you're doing. The newer MaterializedAsyncCallback is preferred over AsyncCallback because you can receive exception messages.

With AsyncCallback, you must explicitly initiate materialization. In your case, you only want 1 response, so you would do .AsyncCallback(...).SingleOrDefault(). In other scenarios where you want a list back, you would do .AsyncCallback(...).ToList(). This is a normal part of how LINQ works, called deferred execution. It allows you to compose a query in multiple pieces (if necessary) without having the query constantly executing before it's fully built - you have control over when the query executes.

@JoeMayo
Mar 21, 2013 at 11:28 PM
Ah, thanks Joe.

I thought MaterializedAsyncCallback was a part of Linq.

I downloaded the latest version of Linq2Twitter, and it started working!