Pijusn
Pijusn

Reputation: 11293

TweetSharp Authorization on WP7 (oAuth)

I am trying to make a WP7 app that would Tweet short messages user wants to. The problem is that I always get Unauthorized response. Here is what I do:

First, I initialize Service:

TwitterService twService;    
twService = new TwitterService(App.TwitterConsumerKey, App.TwitterConsumerSecret);
twService.AuthenticateWith(App.TwitterAccessToken, App.TwitterAccessTokenSecret);

if I use SendTweet I get the Unauthorized response (which is pretty reasonable, I guess - it doesn't know what user it should tweet to). So I have to authorize the user somehow. I need a browser for that. I have created one and called it LoginBrowser. How do I use it? I thought getting the uri like this:

  twService.GetRequestToken((requestToken, response) =>
  {
    if(requestToken == null)
    {
    Console.WriteLine("Getting request token; response: {0}", response.StatusDescription);
    return;
    }
    var uri =  twService.GetAuthorizationUri(requestToken);
    if (uri == null)
      Console.WriteLine("uri is null");
    else
      Console.WriteLine("Uri: {0}", uri.ToString());

  }
  );

This doesn't work. Request token is equal to null and it prints that response is Unauthorized :| What is the proper way of doing this? All documentation I find do not even compile. It seems like TweeSharp has just been updated and now all documentation is out-dated.

Upvotes: 2

Views: 1093

Answers (1)

MatthieuGD
MatthieuGD

Reputation: 4592

Have you an API key for your app ? (http://dev.twitter.com/), I followed mostly this method and it works well. The only difference is that I set to false the IsScriptEnabled attribute on my webbrowser control because of a compatibility issue but I re-enable it by code after the twitter auth page.

Upvotes: 1

Related Questions