4

A few days ago, I posted this question and this question asking about how to post "Hello World" to twitter. I've gotten helpful responses, which have propelled me further along, but I'm still lost.

I need to use OAuth because (as I read it) using username and password is going to be deprecated soon.

I need an example as simple as updating the status with the string constant 'Hello World!'.

My client is specifying that I must use C#.

Community
  • 1
  • 1
Phillip Senn
  • 46,771
  • 90
  • 257
  • 373

5 Answers5

18

Definitely use Linq2Twitter -

http://linqtotwitter.codeplex.com/

It's UpdateStatus method has 11 overloads - the whole implementation is really nice. So you're example would be:

var tweet = twitterCtx.UpdateStatus("Hello world");
philiphobgen
  • 2,234
  • 17
  • 28
  • 1
    @stupid-phil - I've used this! Very very good! Give this man the Rep! – Barrie Reader May 21 '10 at 14:06
  • Thanks Phil! Now: What is linq? – Phillip Senn May 21 '10 at 14:22
  • I'm having a tough time with Linq2Twitter...It seems to also require full trust - seems to be from the Kerr.Credentials piece of it. Do you know if there's a way to either get Linq2Twitter working in medium trust (aka GoDaddy), or a medium trust alternative? – Joe Enos May 21 '10 at 14:23
  • 2
    @cf_PhillipSenn - LINQ will change your life: http://msdn.microsoft.com/en-us/netframework/aa904594.aspx – philiphobgen May 21 '10 at 14:27
  • @Joe Enos - it's not been a problem for me, but here's a link (no pun intended!) that might help http://linqtotwitter.codeplex.com/WorkItem/View.aspx?WorkItemId=24501 – philiphobgen May 21 '10 at 14:33
  • @stupid-phil - Before I even got that far, I tried something different - I removed the Kerr.Credentials DLL, built my own TokenManager, and everything worked perfectly the first try. I like that better for my scenario anyway, since I'm in full control over the keys and secrets. – Joe Enos May 21 '10 at 16:32
9

I'd like to post this here as it took me far too long to work out and is what I would consider to be a minimum requirement for a Hello World to Twitter using Linq2Twitter now that OAuth is mandatory. Hopefully this will be of use to anyone like me who ended up on this page but found it didn't solve their problem.

using LinqToTwitter;
var auth = new SingleUserAuthorizer
{
    Credentials = new InMemoryCredentials
    {
        ConsumerKey = "yourConsumerKey",
        ConsumerSecret = "yourConsumerSecret",
        OAuthToken = "yourOAuthToken",
        AccessToken = "yourAccessToken"
    }
};

var service = new TwitterContext(auth);

var tweet = service.UpdateStatus("hello twitter");
zithery
  • 91
  • 1
  • 1
  • Thanks @zithery! This was a summer project for me back in 2010. – Phillip Senn Jun 19 '13 at 16:52
  • Great post. This level of simple example documentation is missing from the Linq2Twitter doco and needs to be added. Too theoretical and not enough simple practical examples like this. Cheers – Aaron Feb 15 '14 at 08:56
2

What API are you using? have you tried Twitterizer. It should be relatively simple to do.

James
  • 80,725
  • 18
  • 167
  • 237
  • I really liked Twitterizer as well, but what stopped me is that it seems to only work in full trust mode, which (stupid me) I have GoDaddy as my hosting provider, so that's a no-go. – Joe Enos May 21 '10 at 14:01
  • I was going to say that Twitterizer doesn't support OAuth, but apparently Twitterizer2 does! http://www.twitterizer.net/tutorials/getting-started-with-oauth/ – Dave May 21 '10 at 14:04
  • Joe: I don't understand how GoDaddy as a hosting provider fits here. Are you hosting a C# program via GoDaddy? What? – Phillip Senn May 21 '10 at 16:00
  • @cf_PhillipSenn: I have ASP.NET websites that are hosted on GoDaddy, so they are just running normal .NET code. When I wrote an app that used Twitterizer, the app bombed out because it required full trust. I did eventually get it to work with a slightly modified version of Linq2Twitter instead of Twitterizer. – Joe Enos May 21 '10 at 21:55
  • @cf_PhillipSenn: To clarify, since it looks like you're not a .NET guy, C# is one of many languages that compile to .NET code. That .NET code can run in a console app, Windows form, or ASP.NET app (or lots of other types). So the Twitterizer library can be plugged into any type of .NET app, including ASP.NET, and function the exact same way. However, with ASP.NET, in order to do some specific things (reflection, security permission, etc.), you need to run in "full trust", which GoDaddy doesn't allow. So the same DLL that worked in my console app, didn't work once published to the website. – Joe Enos May 21 '10 at 22:00
2

I highly recommend that you use TweetSharp. It is very robust, supports the scenario you specify above (uses OAuth to authenticate).

I've used it on a few pet projects and I've been extremely happy with it. The download comes with a WPF sample application that shows you how to use twitter's OAuth implementation.

Nate
  • 30,286
  • 23
  • 113
  • 184
  • It was but its now out of date, not supported and my old project which used TweetSharp suddenly stopped working mid way through last year as something on Twitter's end changed. – Aaron Feb 15 '14 at 08:57
1

I don't have enough reputation to comment to zithrey but I also agree, linq2twitter's getting started documentation hurts and the project loaded with errors making it unrunnable. Hopefully this will help someone - it uses PIN authorization

static void Main(string[] args)
{
    string ckey = "consumerkey";
    string csecret = "consumersecret";

    var auth = new PinAuthorizer()
    {
        Credentials = new InMemoryCredentials
        {
            ConsumerKey = ckey,
            ConsumerSecret = csecret
        },
        GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
        GetPin = () =>
        {
            Console.WriteLine(
                "\nAfter authorizing this application, Twitter " +
                "will give you a 7-digit PIN Number.\n"
            );
            Console.Write("Enter the PIN number here: ");
            return Console.ReadLine();
        }
    };
    auth.Authorize();
    var twitterCtx = new TwitterContext(auth);
    twitterCtx.UpdateStatus("This status has been created from a C# console app!");
}
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
  • Spot on and I agree. The doco of that project is lame and they need more simple, practical examples added. – Aaron Feb 15 '14 at 08:58