简体   繁体   English

WP7 上的 TweetSharp 授权 (oAuth)

[英]TweetSharp Authorization on WP7 (oAuth)

I am trying to make a WP7 app that would Tweet short messages user wants to.我正在尝试制作一个 WP7 应用程序来发送用户想要的短消息。 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).如果我使用 SendTweet,我会得到Unauthorized响应(我猜这很合理 - 它不知道应该向哪个用户发送推文)。 So I have to authorize the user somehow.所以我必须以某种方式授权用户。 I need a browser for that.我需要一个浏览器。 I have created one and called it LoginBrowser.我创建了一个并将其命名为 LoginBrowser。 How do I use it?我该如何使用它? I thought getting the uri like this:我想像这样得到uri:

  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 :|请求令牌等于 null 并打印响应未经授权:| 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.似乎 TweeSharp 刚刚更新,现在所有文档都已过时。

Have you an API key for your app?您的应用程序有 API 密钥吗? (http://dev.twitter.com/), I followed mostly this method and it works well. (http://dev.twitter.com/),我主要遵循这种方法并且效果很好。 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.唯一的区别是,由于兼容性问题,我将 webbrowser 控件上的 IsScriptEnabled 属性设置为 false,但我在 twitter 身份验证页面之后通过代码重新启用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM