WP7 上的 TweetSharp 授权 (oAuth)

发布于 2024-11-13 21:07:49 字数 986 浏览 2 评论 0原文

我正在尝试制作一个 WP7 应用程序,可以发送用户想要的短信。问题是我总是得到未经授权的回复。这是我所做的:

首先,我初始化服务:

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

如果我使用 SendTweet,我会得到未经授权响应(我猜这是相当合理的 - 它不知道应该向哪个用户发送推文)。所以我必须以某种方式授权用户。我需要一个浏览器。我创建了一个并将其命名为 LoginBrowser。我该如何使用它?我想像这样获取 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());

  }
  );

这不起作用。请求令牌等于 null,并打印响应为未经授权:|这样做的正确方法是什么?我找到的所有文档甚至都无法编译。看起来 TweeSharp 刚刚更新,现在所有文档都已过时。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你穿错了嫁妆 2024-11-20 21:07:49

您的应用程序有 API 密钥吗? (http://dev.twitter.com/),我主要遵循这个方法并且它有效出色地。唯一的区别是,由于 兼容性问题,但我在 Twitter 身份验证页面后通过代码重新启用了它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文