Question

All,

I have the following code in a Windows Console Application. I am using LinqtoTwitter (http://linqtotwitter.codeplex.com/). The line auth.IsAuthorized is returning true. But it fails on the search with Invalid/Expired token error. I have checked and double-checked keys and tokens. Any help would be greatly appreciated.

    static void processTweets()
    {
        var auth = new SingleUserAuthorizer
        {
            Credentials = new InMemoryCredentials
            {
                ConsumerKey = Utility.GetSetting("ConsumerKey"),
                ConsumerSecret = Utility.GetSetting("ConsumerSecret"),
                AccessToken = Utility.GetSetting("Accesstoken"),
                OAuthToken = Utility.GetSetting("AccesstokenSecret")
            }
        };

        auth.Authorize();
        TwitterContext twitterCtx = new TwitterContext(auth);
        if (auth == null || !auth.IsAuthorized)
        {

        }

        var srch =
            (from search in twitterCtx.Search
             where search.Type == SearchType.Search &&
                   search.Query == "LINQ to Twitter" &&
                   search.Count == 7
             select search)
            .SingleOrDefault();

        Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
        srch.Statuses.ForEach(entry =>
            Console.WriteLine(
                "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                entry.StatusID, entry.Source, entry.Text));

    }
Was it helpful?

Solution

Your AccessToken and OAuthToken are backwards. It might be easier to use SingleUserInMemoryCredentials.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top