example needed

Jun 28, 2009 at 12:23 AM

Hey, How would I query the TwitterContext to view the same view as I would get if I logged into twitter?

 

Coordinator
Jun 30, 2009 at 2:16 AM

Hi,

I found an error in the API and fixed it. You can get the fix from ChangeSet 55709:

http://linqtotwitter.codeplex.com/SourceControl/changeset/view/55709

Here's the example, which I've also added to the demos in LinqToTwitterDemo/Program.cs:

        private static void FriendStatusQueryDemo(TwitterContext twitterCtx)
        {
            var friendTweets =
                from tweet in twitterCtx.Status
                where tweet.Type == StatusType.Friends
                select tweet;

            Console.WriteLine("\nTweets for " + twitterCtx.UserName + "\n");
            foreach (var tweet in friendTweets)
            {
                Console.WriteLine(
                    "Friend: " + tweet.User.Name +
                    "\nTweet: " + tweet.Text + "\n");
            }
        }

Joe

Jun 30, 2009 at 5:11 PM
This build requires: Microsoft.Contracts.dll
Coordinator
Jun 30, 2009 at 5:27 PM

Sorry about that - I was doing some testing with Microsoft Contracts and Pex.  I'll take those out and re-deploy.

Joe

Coordinator
Jun 30, 2009 at 5:56 PM

Okay, I've removed Microsoft.Contracts.dll and you can download the latest from here:

http://linqtotwitter.codeplex.com/SourceControl/changeset/view/55761

Joe

Jun 30, 2009 at 10:57 PM

Thanks Joe, explains my problems :D

Jul 1, 2009 at 9:10 PM

Ok there seems to be a problem

 

                If tc.AuthorizedViaOAuth = True Then

                    Dim query = From tweet In tc.Status Where tweet.Type = StatusType.Friends Select tweet

                    For Each tweet In query

                        twitteroutput.InnerHtml &= tweet.User.Name & " - " & tweet.Text & " - " & tweet.CreatedAt & "<br/>"

                    Next

                Else

                    twitteroutput.InnerHtml = "#FAIL"

                End If

 

this just returns the public timeline for me. The user is auth'd so I am not sure what is going on. 

I grabbed the latest source and built that. 

 

Coordinator
Jul 1, 2009 at 10:10 PM

Here's my example from LinqToTwitterDemo/Program.cs, which is working for me. What is different from yours?

        /// <summary>
        /// perform a query using OAuth
        /// </summary>
        /// <param name="twitterCtx">TwitterContext</param>
        private static void HandleOAuthQueryDemo(TwitterContext twitterCtx)
        {
            Console.Write("Consumer Key: ");
            twitterCtx.ConsumerKey = Console.ReadLine();
            Console.Write("Consumer Secret: ");
            twitterCtx.ConsumerSecret = Console.ReadLine();

            string link = twitterCtx.GetAuthorizationPageLink(false, false);

            Console.WriteLine("Authorization Page Link: {0}\n", link);
            Console.WriteLine("Next, you'll need to tell Twitter to authorize access. This program will not have access to your credentials, which is the benefit of OAuth.  Once you log into Twitter and give this program permission, come back to this console and press Enter to complete the authorization sequence.\n\nPress Enter now to continue.");
            Console.ReadKey();

            // launches browser so you can log in and give permissions
            Process.Start(link);

            Console.WriteLine("\nYou should see your browser navigate to Twitter, saying that your application wants to access your Twitter account. Once you've authorized this program, return to this console and press any key to execute the LINQ to Twitter code.");
            Console.ReadKey();
            var uri = new Uri(link);
            NameValueCollection urlParams = HttpUtility.ParseQueryString(uri.Query);
            string oAuthToken = urlParams["oauth_token"];

            twitterCtx.RetrieveAccessToken(oAuthToken);

            if (twitterCtx.AuthorizedViaOAuth)
            {
                var tweets =
                    from tweet in twitterCtx.Status
                    where tweet.Type == StatusType.Friends
                    select tweet;

                tweets.ToList().ForEach(
                    tweet => Console.WriteLine(
                        "Friend: {0}\nTweet: {1}\n",
                        tweet.User.Name,
                        tweet.Text));
            }
        }

Joe

Jul 17, 2009 at 3:32 PM

I am not sure because the line is basically the same as your sample

From tweet In tc.Status Where tweet.Type = StatusType.Friends Select tweet

I will have a further play but the my code is based on yours.

 

 

Coordinator
Jul 17, 2009 at 3:48 PM

Ninjamonk,

AArnot upgraded the project to use DotNetOpenAuth and the code that would be written is different now.  Please download the latest ChangeSet and try looking at the new OAuth examples in Program.cs:

http://linqtotwitter.codeplex.com/SourceControl/changeset/view/56603.

Please let me know how it goes and if you need more help.

Joe