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.