How to verify twitter login credentials

by Viper 5. June 2009 04:53

As more and more have started to integrate Twitter API into the applications and allowing user to post messages and do other twitter related tasks, one of the essential step in the work flow is to verify a user's twitter credentials. There are certain tasks you can perform without logging into API. But when it comes to posting messages or pulling a user's data etc., Twitter API wants the user to be authenticated. Here is a code snippet that shows how you can use Twitter API to verify a user's credentials or verify user's login information.


static TwitterUser VerifyTwitterCredentials(string login, string password)
{
 IFluentTwitter ft = FluentTwitter.CreateRequest();
 ft.AuthenticateAs(login, password);
 ft.Accounts().VerifyCredentials().AsJson();
 var resp = ft.Request();
 TwitterUser tUser = resp.AsUser();
 if (null == tUser)
 {
  var err = resp.AsError();
  Console.WriteLine("Twiiter Error: " + err.ErrorMessage);
 }
 return tUser;
}

When verification fails, you will get a response that will not get converted to TwitterUser object and method will return null object.

Views: 2923

Tags: ,

.Net | C# | VB.Net

Switch statement equivalent in VB.Net

by Viper 29. April 2009 03:33

I have been primarily a C/C++ developer and then moved on to C#. I have done some VB and VB.Net development in the past but not very actively. For last few months I have been involved in lot of VB.Net projects. Every now and then I run into situations where I know how something will be done in C# but not sure how to do it in VB.Net. I mean what will be syntax or statements used in VB.Net that are equivalent to same actions in C#. Yesterday one of my co-workers asked me "What is equivalent of C# Switch statement in VB.Net?". Since I was doing VB.Net development for a prototype project, I quickly answered him "Select Case is equivalent to Switch statement". I thought I will quickly publish this small not showing how Select Case is used in VB.Net.

For example I want to take different action based on what item has been selected in a combo box in my winforms application.

C#
switch(myCombo.SelectedIndex)
{
  case 0: do1(); break;
  case 1: do2(); break;
  case 2: do3(); break;
  default: doNothing(); break;
}
VB.Net
Select Case(myCombo.SelectedIndex)
 Case 0		do1()
 Case 1		do2()
 Case 2		do3()
 Case Else	doNothing()
End Select

Views: 2107

Tags:

VB.Net

WinForms Samples, Tutorials, Demos, Articles and more

by Viper 16. April 2009 19:14

Read, download samples, tutorials etc. for WinForms.

Views: 1211

Tags:

.Net | C# | VB.Net | WinForms

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli