简体   繁体   English

Twitter API身份验证keynotfoundexception

[英]Twitter API authentication keynotfoundexception

I've gone through literally every single tutorial there is about using the twitter api for WP7. 我已经完成了关于在WP7上使用twitter api的每一个教程。 It's my first time using oauth and it can quite confusing. 这是我第一次使用oauth,它可能会令人困惑。 I'm trying to make it so my users can tweet a message and a picture. 我正在尝试这样做,以便我的用户可以发送消息和图片。 I went through this tutorial on oauth and several other ones (but am using this one atm): 我浏览了oauth和其他几个教程(但我使用的是这个atm):

http://sudheerkovalam.wordpress.com/2010/08/28/a-windows-phone-7-twitter-application-part-1/#comment-251 http://sudheerkovalam.wordpress.com/2010/08/28/a-windows-phone-7-twitter-application-part-1/#comment-251

Also found some great help on stackoverflow about posting photos here: 在这里发布照片的stackoverflow上也找到了一些很棒的帮助:

Upload image directly to twitter 将图像直接上传到twitter

But for the authentication portion described in the blog post above I keep on getting a "KeyNotFoundException" on the line " OAuthTokenKey = parameters["oauth_token"]; " I've tried to figure it out but can't come up with anything being my first time doing this. 但是对于上面博客文章中描述的身份验证部分,我继续在“ OAuthTokenKey = parameters["oauth_token"];行上获得”KeyNotFoundException“ OAuthTokenKey = parameters["oauth_token"]; ”我试图找出它,但无法想出任何东西我第一次这样做。 There doesn't seem to be much help anywhere else because every tutorial is uses different techniques that are hard to put together, so I came to you guys. 在其他地方似乎没有太多帮助,因为每个教程都使用了难以组合的不同技术,所以我来找你们。 If you know a fix, please let me know! 如果您知道修复,请告诉我! Or if you know of a recent tutorial out there that works great right now please let me know! 或者,如果你知道最近的教程现在很好用,请告诉我!

I updated the code at Upload image directly to twitter for the LINQ to Twitter sample, repeated here for convenience: 我将上传图片的代码直接更新到了Twitter的LINQ to Twitter示例,为方便起见,在此处重复:

    private void PostButton_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrWhiteSpace(TweetTextBox.Text))
            MessageBox.Show("Please enter text to tweet.");

        ITwitterAuthorizer auth = SharedState.Authorizer;
        if (auth == null || !auth.IsAuthorized)
        {
            NavigationService.Navigate(new Uri("/OAuth.xaml", UriKind.Relative));
        }
        else
        {
            var twitterCtx = new TwitterContext(auth);

            var media = GetMedia();

            twitterCtx.TweetWithMedia(
                TweetTextBox.Text, false, StatusExtensions.NoCoordinate, StatusExtensions.NoCoordinate, null, false,
                media,
                updateResp => Dispatcher.BeginInvoke(() =>
                {
                    HandleResponse(updateResp);
                }));
        }
    }

There's a sample on this page that you can load and test: 此页面上有一个示例,您可以加载和测试:

http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20Samples http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20Samples

I think part of the problem might have been that I posted a synchronous sample on the previous page, which works with client and Web apps, but isn't appropriate for WP7. 我认为部分问题可能是我在上一页上发布了一个同步样本,它适用于客户端和Web应用程序,但不适合WP7。

An important tip when doing OAuth in Windows Phone is that you must set the clock on the emulator to your current time. 在Windows Phone中执行OAuth时的一个重要提示是,必须将模拟器上的时钟设置为当前时间。 Watch the time zone too, which can throw things off. 同时观看时区,这可能会让人失望。 OAuth uses a time stamp that must be in sync with the Twitter Server. OAuth使用必须与Twitter服务器同步的时间戳。

I also recently fixed a couple problems related to recent changes in Twitter, so if you run into problems on other queries, the downloadable source is here, where you can get the latest changes: 我最近还解决了一些与Twitter最近的变化相关的问题,因此如果您遇到其他查询的问题,可下载源就在这里,您可以在这里获得最新的更改:

http://linqtotwitter.codeplex.com/SourceControl/list/changesets http://linqtotwitter.codeplex.com/SourceControl/list/changesets

Joe

Try this for authentication, it worked great for me and I'm using it in my app: 尝试这个进行身份验证,它对我很有用,我在我的应用程序中使用它:

http://igrali.com/2012/06/17/twitter-authentication-from-windows-phone-app/ http://igrali.com/2012/06/17/twitter-authentication-from-windows-phone-app/

After that, you'll have the needed info to upload a photo using one of the samples offered here. 之后,您将获得使用此处提供的示例之一上传照片所需的信息。

Have in mind that the first blog post you mentioned in your question is from 2010. Things may have changed on Twitter side since then (and probably have!). 请记住,您在问题中提到的第一篇博文是从2010年开始的。自那时起,Twitter方面的情况可能已发生变化(可能还有!)。

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

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