Reputation: 3218
I'm using TweetSharp in a WPF app to connect to a user Twitter account and retrieve tweets. I'm doing the login using the OAuth and Pin verification, using the following code:
Showing the login page
TwitterService _twitterService = new TwitterService(_consumerKey, _consumerSecret);
_requestToken = _twitterService.GetRequestToken();
Uri uri = _twitterService.GetAuthorizationUri(_requestToken);
webBrowser.Navigate(uri);
Submitting the Pin for token and tokenSecret exchange:
OAuthAccessToken _access = _twitterService.GetAccessToken(_requestToken, _pin);
if(_twitterService.Response.StatusCode == HttpStatusCode.OK) {
_twitterService.AuthenticateWith(_access.Token, _access.TokenSecret);
// Connection successful
} else {
// Error connecting
}
After this I save the token
and tokenSecret
in the database for future use. Next time the user enters the app he shouldn't be asked to give permissions a second time, and since I have the consumerKey
, consumerSecret
, token
and tokenSecret
I think I should be able to establish a connection without requesting for an OAuth.
So, my questions are:
How do I connect to Twitter using TweetSharp and having the token
and tokenSecret
?
Also, how do I verify if the tokens are valid?
Upvotes: 1
Views: 2224
Reputation: 3218
I figured how to do the authentication. I thought it was not working because the TwitterService response always came back null, but it actually retrieves the fetched data. So in short, the answer is this:
TwitterService _twitterService = new TwitterService();
_twitterService.AuthenticateWith(_cosKey, _cosSecret, _tkn, _tknSecret);
IEnumerable<TwitterStatus> tweets = _twitterService.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());
// tweets count = 20
I still don't know how to check if the TwitterService
is valid if incorrect token
and tokenSecret
are passed.
Upvotes: 1