WP7 上的 TweetSharp 授权 (oAuth)
我正在尝试制作一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的应用程序有 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.