Possible to use from a webservice?

Nov 8, 2012 at 4:03 PM

Hi,

Is it possible to use LinqToTwitter inside a webserice? The reason I ask is because I run the samples it navigates me to my twitter page where i have to authorize the application access - this will of course not work when you are using a web service without any user input via the user interface.

Thanks

Thomas

Nov 8, 2012 at 4:40 PM

Hi - I think I found the solution. Can someone please verify that this is the correct way of doing it (see code below)? My requirements is to show all the tweets on the persons that I am following. What I am most concern about is "TwitterContext(auth, "https://api.twitter.com/1/", https://search.twitter.com/))" which I am not really sure about (but it seems to work).

By the way - fantastic library - thanks for that!


 

var auth = new SingleUserAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "xxx",
                    ConsumerSecret = "xxx",
                    OAuthToken = "xxx",
                    AccessToken = "xxx"
                }
            };

            using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/", "https://search.twitter.com/"))
            {
                var queryResponse =
               from tweet in twitterCtx.Status
               where tweet.Type == StatusType.Home
               select tweet;

                var tweets = queryResponse.ToList();

 


Coordinator
Nov 11, 2012 at 5:18 AM
Edited Nov 11, 2012 at 5:19 AM

Hi,

There's a problem here that might show up in unexpected ways if you're using the latest release. LINQ to Twitter is now using Twitter API v1.1.  However, your code is using Twitter API v1.0 urls when instantiating TwitterContext. It's best to just instantiate TwitterContext with the IAuthorizer only overload (i.e. new TwitterContext(auth)). TwitterContext will default to the v1.1 URLs. The problem might occur in the difference between Twitter API v1.0 and Twitter API v1.1 where some responses might not be populated correctly because the Twitter API format is different.

If you're using an older version of LINQ to Twitter, then you're using Twitter API v1.0 and your code isn't a problem - right now. Twitter API v1.0 is deprecated and will cease to function in less than 6 months. So, if you've written code for an older version, it will suddenly stop working if you didn't know about this. Here's my blog post on the changes and how they affect LINQ to Twitter:

Converting LINQ to Twitter to Twitter API v1.1

@JoeMayo


Nov 12, 2012 at 1:58 PM

Hi,

Thank you for the warning!

So this is ok?

var auth = new SingleUserAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "xxx",
                    ConsumerSecret = "xxx",
                    OAuthToken = "xxx",
                    AccessToken = "xxx"
                }
            };

            using (var twitterCtx = new TwitterContext(auth))
            {
                var queryResponse =
               from tweet in twitterCtx.Status
               where tweet.Type == StatusType.Home
               select tweet;

                var tweets = queryResponse.ToList();

Coordinator
Nov 12, 2012 at 11:07 PM

That looks pretty good.

@JoeMayo