【问题标题】:How to authenticate Twitter with TweetSharp如何使用 TweetSharp 对 Twitter 进行身份验证
【发布时间】:2013-03-02 18:24:27
【问题描述】:

我创建了一个新应用程序并在 Twitter 上注册了它以获取消费者密钥、消费者密钥秘密、令牌和令牌秘密。然后我添加了对 TweetSharp 的引用。接下来我使用来自https://github.com/danielcrenna/tweetsharp 的代码,上面写着“验证客户端应用程序(即桌面)”。

它总是打开的页面在标题栏中没有键。我注意到第 1 步中的 oAuthRequestToken 有两个用于令牌/令牌秘密的属性,但都没有设置。所以我手动添加了行来设置这两个。我又试了一次。这次在浏览器中打开的 Url 看起来是完整的。

我所看到的只是“哇!此页面的请求令牌无效。它可能已被使用,或者由于太旧而过期。请返回将您发送到此处的站点或应用程序并尝试再次;这可能只是一个错误。”

我已尝试重新创建令牌,并发送密钥和令牌以防我不理解它。我完全迷路了。刚开始不会这么难!

有什么想法吗?

【问题讨论】:

    标签: c# tweetsharp


    【解决方案1】:

    我不确定您的问题出在哪里,但我会尽力提供帮助。这是我测试并为我工作的样本。我是从社区那里得到的。不要忘记将密钥放在 app.config 文件中。

            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
            twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
            twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config
    
            TwitterService twitterService = new TwitterService(twitterClientInfo);
    
    
            //Now we need the Token and TokenSecret
    
            //Firstly we need the RequestToken and the AuthorisationUrl
            OAuthRequestToken requestToken = twitterService.GetRequestToken();
            string authUrl = twitterService.GetAuthorizationUri(requestToken).ToString();
    
            //authUrl is just a URL we can open IE and paste it in if we want
           Process.Start(authUrl); //Launches a browser that'll go to the AuthUrl.
    
           //Allow the App
           //ask for the pin
           //string pin = ...
    
    
           OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin);
    
           string token = accessToken.Token; //Attach the Debugger and put a break point here
           string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here
    
    
            twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
    

    希望对您有所帮助。 祝你好运。

    【讨论】:

    • 抱歉,这里的密码是什么?
    • 很抱歉回答迟了。该引脚是身份验证的一部分,出于逻辑原因,我提供了没有它的代码:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2013-11-27
    • 2018-05-03
    • 2012-08-06
    • 1970-01-01
    • 2011-08-04
    相关资源
    最近更新 更多