get my timeline

Feb 18, 2014 at 1:24 AM
Ok, i am going to ask a newb question. How do I get my timeline? I've got the code below. I have tokens and keys that are provided to me via Xamarin.Auth running in iOS & Android. as far as I can tell, I have successfully connected, so my keys should be correct. I get to the point where I run the linq query and nothing happens. Execution just disappears. Any suggestions are appreciated.
        //has the user already authenticated from a previous session? see AccountStore.Create().Save() later
        IEnumerable<Account> accounts = AccountStore.Create(this).FindAccountsForService("Twitter");

        //check the account store for a valid account marked as "Twitter" and then hold on to it for future requests
        foreach (Account account in accounts)
        {
            loggedInAccount = account;
            break;
        }
        var twitterAuth = new LinqToTwitter.XAuthAuthorizer();
        var cred = new LinqToTwitter.InMemoryCredentialStore();
        cred.ConsumerKey = loggedInAccount.Properties["oauth_consumer_key"];
        cred.ConsumerSecret = loggedInAccount.Properties["oauth_consumer_secret"];
        cred.OAuthToken = loggedInAccount.Properties["oauth_token"];
        cred.OAuthTokenSecret = loggedInAccount.Properties["oauth_token_secret"];
        var auth = new LinqToTwitter.SingleUserAuthorizer()
        {
            CredentialStore = cred,
        };
        var TwitterCtx = new LinqToTwitter.TwitterContext(auth);
        Console.WriteLine(TwitterCtx.User);
        var tl = (from tweet in TwitterCtx.Status
                  where tweet.Type == LinqToTwitter.StatusType.Home
                  select tweet).ToList<LinqToTwitter.Status>();
        Console.WriteLine("Tweets Returned: " + tl.Count.ToString());
Coordinator
Feb 18, 2014 at 2:45 AM
Edited Feb 18, 2014 at 2:46 AM
Hi Wally,

Since LINQ to Twitter v3.0 is async, you should await the query, like this:
        var tl = 
             await
            (from tweet in TwitterCtx.Status
             where tweet.Type == LinqToTwitter.StatusType.Home
             select tweet)
            .ToListAsync();
Notice how I prefixed the query with the await keyword. Also, I changed your LINQ to Objects ToList() operator to the LINQ to Twitter ToListAsync() operator.

Note: That XAuthAuthorizer is dead code, but probably won't work anyway because you need permission from Twitter to use it.

@JoeMayo
Feb 18, 2014 at 2:01 PM
Thanks Joe. Unfortunately, I was getting an error message on that syntax, so it would not compile. Here is the error message:
'System.Linq.IQueryable<LinqToTwitter.Status>' does not contain a definition for 'ToListAysnc' and no extension method 'ToListAysnc' accepting a first argument of type 'System.Linq.IQueryable<LinqToTwitter.Status>' could be found (are you missing a using directive or an assembly reference?)

As a result, I went to the syntax I showed above. Any idea on this? My entire code in Xamarin.Android is below. The VS editor hints that there is a namespace that may be missing, but I am unsure which one to add. I think I've added just about all of them. :-)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using System.Linq;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

using LinqToTwitter.Common;
using LinqToTwitter.Json;
using LinqToTwitter.Net;
using LinqToTwitter.Security;
using LinqToTwitter.Serialization;

using Xamarin.Auth;

namespace oAuthAndroid
{
[Activity(Label = "Twitter Timeline")]
public class ReadTwitterTimeline : ListActivity
{
    Account loggedInAccount;

    async protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        //has the user already authenticated from a previous session? see AccountStore.Create().Save() later
        IEnumerable<Account> accounts = AccountStore.Create(this).FindAccountsForService("Twitter");

        //check the account store for a valid account marked as "Twitter" and then hold on to it for future requests
        foreach (Account account in accounts)
        {
            loggedInAccount = account;
            break;
        }
        var cred = new LinqToTwitter.InMemoryCredentialStore();
        cred.ConsumerKey = loggedInAccount.Properties["oauth_consumer_key"];
        cred.ConsumerSecret = loggedInAccount.Properties["oauth_consumer_secret"];
        cred.OAuthToken = loggedInAccount.Properties["oauth_token"];
        cred.OAuthTokenSecret = loggedInAccount.Properties["oauth_token_secret"];
        var auth = new LinqToTwitter.PinAuthorizer()
        {
            CredentialStore = cred,
        };
        var TwitterCtx = new LinqToTwitter.TwitterContext(auth);
        Console.WriteLine(TwitterCtx.User);
        var tl = await
            (from tweet in TwitterCtx.Status
             where tweet.Type == LinqToTwitter.StatusType.Home
             select tweet).ToListAsync();
        Console.WriteLine("Tweets Returned: " + tl.Count.ToString());
        // Perform any additional setup after loading the view
    }
}
}
Coordinator
Feb 18, 2014 at 4:54 PM
The error message has ToListAsync misspelled - ... for 'ToListAysnc' and ..., but your code sample has it spelled correctly. Is it possible that you have some code somewhere else with the misspelling?
Feb 18, 2014 at 9:30 PM
The code that I have in my class file is above. The project was just created recently in VS 2013 using the defaults, so I would expect the project to be correct (.net 4.5.1). The l2t library was download from nuget last weekend. it shows as v3.0.2. I killed that reference and downloaded from codeplex. I still got the same error.

The error message in VS comes up in the .ToListAsync() query. That is the only class that uses l2t, so I don't think the error is happening elsewhere. VS indicates that the twitter query is where the problem occurs. Interestingly, I am getting the same error in a companion project that does the exact same thing but runs in iOS, using Xamarin.iOS.

I'm stumped on this. I think that this is something that I am going, but can't figure it out. I'd be glad to share my project(s) if you would like to see them.

Thoughts:
  1. Is there any thing that is missing with regards to the namespaces?
  2. I'm using the pcl version of the library. Should I be using something different?
Wally
Feb 19, 2014 at 2:06 PM
Ok, i went back, created a new project, and did not go through nuget to get the library. Now, everything compiles with .ToListAsync. I get a new problem now. Here is the error message:
System.TypeLoadException: Could not load type 'LinqToTwitter.SingleUserAuthorizer' from assembly 'LinqToTwitterPcl, Version=3.0.2.12654, Culture=neutral, PublicKeyToken=957107be965c25d9'.

Is there a different authorizer I should use from a Xamarin solution?

Instead of using the pcl library, should I use one of the other compiled libraries?

Wally