Simple status update in Twitter

Mar 23, 2012 at 8:36 PM

Hello! I'm trying to create a console application to simply update an status in my twitter account, I've seen similar discussions throughout the forum, however, I'm new to Twitter AND C#. Anyway I'm using the LinqtoTwitterDemo and now it runs without errors, my question is very simple: What do I have to change (maybe in the method DumpJoeFriends) to update the status of my account (named ozigee123 or whatever). My application was created, I have the consumerKey and consummerSecret, etc.

Thank you :)

Coordinator
Mar 23, 2012 at 8:49 PM

Hi,

There's a method on the TwitterContext named UpdateStatus, which you would use like this:

twitterCtx.UpdateStatus("<Your text goes here>");

You'll need to authorize with OAuth for this to work, so take the PIN option in the demo.  After you're authorized, you can call UpdateStatus.

There's an example of this in the StatusDemos.cs file.  There's more info here too:

http://linqtotwitter.codeplex.com/wikipage?title=Updating%20Statuses&referringTitle=Making%20Status%20Queries%20and%20Calls

Joe

Mar 23, 2012 at 9:25 PM

Wow! That was fast! Thank you for your response Joe.

Please, let me know if I got this correctly: I have to use the PIN option (the one that asks for a 7 digits number) right? Is there a way to avoid the user to type this and just catch it from a returned value?

Do I have to specify somewhere the name of the account of which status is going to be updated?

 

Thanks,

Ozi

Coordinator
Mar 23, 2012 at 9:38 PM

Correct, PIN is the one that asks the user to enter the number.  There are different authorizers, but for a client application, like WPF or Console, PIN is the only one that allows you to serve multiple users.  PIN is a work-around for client apps because OAuth was originally envisioned as a way for Web apps to collaborate without forcing the user to share their password.  Essentially, the security model is designed with the best interest of the end-user in mind.

If you're building a Web application, then you would use the Web authorizer, which handles all of the HTTP redirection for you (no PIN required).  I've temporarily pulled the Web, Silverlight, and WP7 samples because they were based on Public status queries, which Twitter will be deprecating soon, and I need to re-write them. 

Here's more info on Twitter API security, OAuth, and the LINQ to Twitter implementation:

http://linqtotwitter.codeplex.com/wikipage?title=Securing%20Your%20Applications&referringTitle=Documentation

Joe

Mar 23, 2012 at 9:51 PM

I see, but, what if I'm the only one meant to use the application? I only want to create a program that updates my own status in Twitter, no multiple users, would the PIN still be necessary? Do I have to specify in the app.config the name of the account to be updated?

Ozi

Coordinator
Mar 23, 2012 at 10:11 PM

In that case, you only need to authenticate one time, but set a breakpoint, grab all the credentials, and re-use them every time.  Twitter doesn't expire tokens.  Another option is called Single User Authorization, which is made specially for these scenarios and you would use the Single user authorizer instead of PIN.

Joe

Mar 23, 2012 at 10:29 PM

Joe, this works fine!! I was able to update my status either with or without PIN. Thank you very much. I would like to ask one last question, sorry if it's too silly, but, how did the application know which account to update? I never specified it. Is ti because it was my account the one that got the credentials I'm using? Or maybe cause it was me who was logged in when the application ran?

Thanks again,

Ozi

Coordinator
Mar 23, 2012 at 10:49 PM

Once the authorizer is loaded with credentials, you can re-use the same instance without re-authenticating.  Did you populate all four credential items?  If only two (ConsumerKey and ConsumerSecret), then LINQ to Twitter would initiate the authentication sequence, but if you load all four credential keys/tokens you can use the authorizer without re-authenticating.  After the authentication sequece completes successfully, all four credential items will be populated and you can get to them via auth.Credentials.

LINQ to Twitter will operate on behalf of the authenticated user.  So, if the code calls Authenticate, you'll be redirected to Twitter to authorize the application.  You'll have to be logged in to authenticate.  The logged in user who gives the application permission will be the user that LINQ to Twitter operates on behalf of.  If you were the one logged in when giving permission, then calls to UpdateStatus will be with your account.

Joe

Mar 23, 2012 at 11:24 PM

Yes, I populated all four credentials, by doing this, I'm able to update my status even without being logged in, am I right?

Ozi

Coordinator
Mar 23, 2012 at 11:46 PM

Correct.

Joe

Mar 28, 2012 at 11:22 PM
Edited Mar 28, 2012 at 11:56 PM

I found it