-1

This my button click code, but the status is not updating in Twitter. Please help me out.

protected void btnTwitt_Click(object sender, EventArgs e)
{
    string twitterMsg = txtShout.Text;
    OAuthTokens tokens = new OAuthTokens();
    tokens.AccessToken = "xxxxx";
    tokens.AccessTokenSecret = "yyyy";
    tokens.ConsumerKey = "tttt";
    tokens.ConsumerSecret = "hhhh";
    TwitterResponse<Twitterizer.TwitterStatus> tweetResponse = 
    Twitterizer.TwitterStatus.Update(tokens, twitterMsg);
    lblTwitMsg.Text = "Your have shout successfully on http://twitter.com/" + "";
}
4

4 回答 4

1

我想你正在关注这个网站http://www.twitterizer.net/

按照以下链接获取详细信息..我还没有尝试过,但这些有关于实施的详细信息..

http://www.dougv.com/2009/07/01/posting-status-updates-tweets-to-a-twitter-profile-via-asp-net/

http://dotnetguts.blogspot.com/2010/05/tweet-posting-from-aspnet-using-oauth.html

你为什么不试试这个???这是 twitter 小部件代码,这也将执行相同的操作.. 您必须登录一次,然后您才能发布/分享...

<a href="http://twitter.com/share" class="twitter-share-button"
data-url=""
data-text="testing tweet post" data-count="none" data-via="niranjankala" data-counturl="">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js">
</script>

它正在工作.. 在此处输入图像描述

希望这有帮助..

于 2011-11-10T09:23:25.407 回答
0

为了确定您的代码有什么问题,您应该检查结果状态。

protected void btnTwitt_Click(object sender, EventArgs e)
{
     string twitterMsg = txtShout.Text;

    OAuthTokens tokens = new OAuthTokens();
    tokens.AccessToken = "xxxxx";
    tokens.AccessTokenSecret = "yyyy";
    tokens.ConsumerKey = "tttt";
    tokens.ConsumerSecret = "hhhh";
    TwitterResponse<Twitterizer.TwitterStatus> tweetResponse = Twitterizer.TwitterStatus.Update(tokens, twitterMsg);
    if (tweetResponse.Result == RequestResult.Success)
    {
        lblTwitMsg.Text = "Your have shout successfully on http://twitter.com/";
    }
    else
    {
        lblTwitMsg.Text = string.format("The tweet could not be posted: {0}", tweetResponse.ErrorMessage);
    }
}

tweetResponse.Result物业还将让您了解发生了什么。

如果您还有其他问题,您应该在论坛上联系 Twitterizer 支持(实际上是我):http ://forums.twitterizer.net/ 。

于 2011-11-10T14:32:00.307 回答
0

In thye place of "tttt" you need to enter you consumer key and "hhhh" you need to insert your secret key.I think you have updated else update them with yours.Or else you can get one from here https://dev.twitter.com/apps/new

Here is the entire code you can just copy and paste it as I have done it vb and you can convert with C# converter from here:C# Converter

First download twitterizer.dll from here http://www.twitterizer.net/downloads/ Add a new class file I named it as (BasPage.vb)

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Diagnostics
Imports Twitterizer

Public Class BasePage
    Inherits System.Web.UI.Page

    Protected Sub DisplayAlert(ByVal msg As String)
        ClientScript.RegisterStartupScript(Me.GetType(), Guid.NewGuid().ToString(), String.Format("alert('{0}');", msg.Replace("'", "\'").Replace(Constants.vbCrLf, "\n")), True)
    End Sub

    Protected Function GetCachedAccessToken() As OAuthTokens
        If Session("AccessToken") IsNot Nothing Then
            Return CType(Session("AccessToken"), OAuthTokens)
        Else
            Return Nothing
        End If
    End Function

    Public Function GetCachedUserId() As ULong
        If Session("GetCachedUserId") IsNot Nothing Then
            Return Convert.ToUInt64(Session("GetCachedUserId"))
        Else
            Return ULong.MinValue
        End If
    End Function

    Protected Sub CreateCachedAccessToken(ByVal requestToken As String)
        Dim ConsumerKey As String = ConfigurationManager.AppSettings("ConsumerKey")
        Dim ConsumerSecret As String = ConfigurationManager.AppSettings("ConsumerSecret")

        Dim responseToken As OAuthTokenResponse = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken)

        'Cache the UserId
        Session("GetCachedUserId") = responseToken.UserId

        Dim accessToken As New OAuthTokens()
        accessToken.AccessToken = responseToken.Token
        accessToken.AccessTokenSecret = responseToken.TokenSecret
        accessToken.ConsumerKey = ConsumerKey
        accessToken.ConsumerSecret = ConsumerSecret

        Session("AccessToken") = accessToken
    End Sub

    Protected Function GetTwitterAuthorizationUrl() As String
        Dim ConsumerKey As String = ConfigurationManager.AppSettings("ConsumerKey")
        Dim ConsumerSecret As String = ConfigurationManager.AppSettings("ConsumerSecret")

        Dim reqToken As OAuthTokenResponse = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret)
        Return "https://twitter.com/oauth/authorize?oauth_token=" & reqToken.Token
    End Function
End Class

And next add a button and paste this code:

 Protected Sub ibSignInWithTwitter_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibSignInWithTwitter.Click
        Response.Redirect(MyBase.GetTwitterAuthorizationUrl())
  End Sub

And last in your web.config file you need to add this:

        <add key="ConsumerKey" value="you consumer key"/>
        <add key="ConsumerSecret" value="you consumersecret key"/>
        <add key="Twitterizer2.EnableStatisticsCollection" value="false"/>

If you have any problem let me know.Hope it helps you.

于 2011-11-10T09:30:15.047 回答
-1
 try getting oauth token first using this.sorry if it doesnot help ..   

var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
     var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
     //Step 1: Get Request Token
      string callbackAddress = "http://xxx.co/folder/Twitter.aspx";
     OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callbackAddress);
    //  Step 2: Redirect User to Requested Token
            Response.Redirect("http://twitter.com/oauth/authorize?oauth_token=" + RequestToken.Token);
于 2011-11-10T12:48:58.277 回答