-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/" + "";
}
Smi
  • 13,850
  • 9
  • 56
  • 64
sambit
  • 19
  • 3
  • I think no one can help you fix this issue if you don't supply more information. – ChristiaanV Nov 10 '11 at 08:25
  • what u want more info please specify.. – sambit Nov 10 '11 at 08:27
  • can u please share ur mail id?? i will post u .. – sambit Nov 10 '11 at 08:30
  • All answers should be posted here so we all can help and/or learn. Please describe what error message you are receiving. You may also want to show more code so we can see how the snippet you posted is actually used. – John Conde Nov 10 '11 at 16:49
  • If you want to use Twitter OAuth, can follow this link http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/ Hope this will help you. – Login Radius Dec 04 '11 at 12:51

4 Answers4

1

i think you are following this website http://www.twitterizer.net/

follow the following links for detailed information.. i have not tried yet but these have detailed information about the implementation..

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

why do you not try this??? this is twitter widget code this will also do the same.. you have to login once then you are able to post/share with it...

<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>

and it is working.. enter image description here

hope this help..

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • i have already followed this website (http://dotnetguts.blogspot.com/2010/05/tweet-posting-from-aspnet-using-oauth.html) and applied same code in my asp.net page but its not working after aunthetication its redirecting to my call back url page. – sambit Nov 10 '11 at 10:10
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.

coder
  • 13,002
  • 31
  • 112
  • 214
  • ya alraedy i have updated with original but here for security reason i have not put – sambit Nov 10 '11 at 10:02
  • Are you getting any error messages have you checked that by placing the breakpoints? – coder Nov 10 '11 at 10:10
  • ya i checked with putting break point that if(Request.QueryString["oauth_token"] == null) here its going inside and asking for authorization after clicking authorization its redirecting to my call back url becoz its value is null i mean its not a valid user...so can u plz clarify how this Request.QueryString["oauth_token"] == null) oauth_token will be some value..thanks a alot for reply – sambit Nov 10 '11 at 10:54
  • Wow, @user944919, Twitterizer2.EnableStatisticsCollection. I haven't seen that in a long time. I love you for using Twitterizer for so long! – Ricky Smith Nov 10 '11 at 14:34
  • It makes much easier to post your status messages. – coder Nov 10 '11 at 14:49
  • FYI, You don't need EnableStatisticsCollection anymore. That was a (very) short lived thing. It was a bad solution to a problem that doesn't really exist. – Ricky Smith Nov 18 '11 at 19:39
0

In order to determine what is wrong with your code, you should check the result status.

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);
    }
}

The tweetResponse.Result property will also give you an idea as to what happened, too.

If you have additional questions, you should contact Twitterizer support (it's actually me) on the forums: http://forums.twitterizer.net/.

Ricky Smith
  • 2,379
  • 1
  • 13
  • 29
-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);
Karthik
  • 2,391
  • 6
  • 34
  • 65
  • hii karthi, i used ur code,i set some diff website in my callbackAddress.After clicking the Authorize APP button it is redirecting to my callbackAddress website so i am not able enter my status in my asp .net page..plz help me regarding this – sambit Nov 11 '11 at 04:36
  • @sambit set the call back url to the page where you wil enter tweets.. after authorization it automatically redirects to the page u specifed..r u getting oauth tokens now – Karthik Nov 11 '11 at 04:59
  • check this out -http://www.tonyamoyal.com/2009/08/17/how-to-quickly-set-up-a-test-for-twitter-oauth-authentication-from-your-local-machine/ – Karthik Nov 11 '11 at 05:01
  • ya i m getting oauth tokens but when i am setting my localhost addreess(http://localhost:4117/StatusUpdate.aspx) in callback aaddress it is not allowing me can u plz help me on this – sambit Nov 11 '11 at 05:02
  • this my token details: https://twitter.com/oauth/authorize?oauth_token=uYsx91t7ezoGbgKQ14vLyYgl6DTCJIEudbFNDvBSKM – sambit Nov 11 '11 at 05:04
  • try this...i think it may work if u get the call back url right...if this post actually helped you then y is it marked as not useful :-(...http://books.google.co.in/books?id=1Gq4Ktxz2yIC&pg=PT125&lpg=PT125&dq=call+back+address+of+local+machine+in+twitter&source=bl&ots=tW9newDPWo&sig=lKrfTkMLhSAIMZcN-me8PpUz-Vw&hl=en&ei=Uqu8TsD0DIjtrAfFkt3TAQ&sa=X&oi=book_result&ct=result&resnum=6&ved=0CFkQ6AEwBQ#v=onepage&q&f=false – Karthik Nov 11 '11 at 05:06
  • i think u have specified the call back url as facebook.com instead set it to the asp.net page where u r gonna add ur tweets..try googling a bit u can find it out – Karthik Nov 11 '11 at 05:16
  • i shortened my localhost url and put the same in callbackAddress both place in dev.twitter app setting and my asp .net page but after redirecting it is showing 404-not found msg in web page..this my address url http://tinyurl.com/bs54745?oauth_token=7CmYnq6yuvXOr9jAm2P10yUwhKyzlnZnlMdqCmJyvz8&oauth_verifier=KLAJ5zZoFYSLm0Wt7Ie8fbIFHyVagvQxpXCTGd84Yo – sambit Nov 11 '11 at 05:35
  • is the cal back url a page in local machine or a live server – Karthik Nov 11 '11 at 05:47