[SOLVED] Check User Tokens are valid or not using Twitter Api

Issue

I have a Asp.Net application that will post tweets in twitter.
I’m using Twitterizer2 for doing this.

First time when the user uses the application, he will be redirected to twitter for authentication.
And then the user-token will be stored in my application , so that the user will never be asked again to login to twitter.
This is working fine.

Now i want to validate the user-tokens before posting (ie valid token or not) . Is there any way to do this validation?

Solution

I found out the code for validating tokens in another question.
The Twitterizer Api itself had the Methods to validate the User tokens.
The code is as follows:

Twitterizer.OAuthTokens token = new Twitterizer.OAuthTokens();
token.ConsumerKey = this.AppId;
token.ConsumerSecret = this.AppSecret;
token.AccessToken = userToken;
token.AccessTokenSecret = userSecret;

Twitterizer.TwitterResponse<Twitterizer.TwitterUser> response =
    Twitterizer.TwitterAccount.VerifyCredentials(token);

if (String.IsNullOrEmpty(response.ErrorMessage))
{
    //This is a valid token
}
else
{
    //Invalid token
}

Answered By – shajivk

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *