在Asp.net中集成Twitter

时间:2014-04-11 11:35:13

标签: asp.net twitter twitter-oauth twitterizer

protected void Page_Load(object sender, EventArgs e)
        {
            var oauth_consumer_key = "pUw6DN1vh2PRhqIQd0w";
            var oauth_consumer_secret = "uCrFLs6x3LlKd6G9YZ2XSzvjiQZmfAM1z3TTEus";

            if(Request["oauth_token"] == null)
            {
                OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    Request.Url.AbsoluteUri);

                Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}",
                    reqToken.Token));
            }
            else
            {
                string requestToken = Request["oauth_token"].ToString();
                string pin = Request["oauth_verifier"].ToString();
                var tokens = OAuthUtility.GetAccessToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    requestToken,
                    pin);
                OAuthTokens accesstoken = new OAuthTokens()
                {
                    AccessToken = tokens.Token,
                    AccessTokenSecret = tokens.TokenSecret,
                    ConsumerKey = oauth_consumer_key,
                    ConsumerSecret = oauth_consumer_secret
                };

                TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
                    accesstoken,
                    "Testing!! It works (hopefully).");

                if(response.Result == RequestResult.Success)
                {
                    Response.Write("we did it!");
                }
                else
                {
                    Response.Write("it's all bad.");
                }

            }           
        }

我已经在asp.net中集成了twitter。 但总是给我回应。结果&#39; UNKNOWN&#39; 消息&#34;一切都很糟糕。&#34; 我不知道从我的结局发生了什么。 Install-Package twitterizer - 版本2.4.2 请参阅此链接 Twitter Integration Link

2 个答案:

答案 0 :(得分:1)

这是因为访问未经授权。请检查响应对象的 TwitterStatus

或者,您可以查看Updated Twitterizer Integration Code

答案 1 :(得分:0)

如果您在localhost中运行应用程序,则必须在twitter应用程序URL中指定localhost url和port,如127.0.0.1:3000。我的问题用这个解决了。