Search This Blog

Friday, October 14, 2011

How to Update Twitter using ASP and Twitter API

In aspx file post

<..form id="form1" runat="server1">
    <..div>
        <..asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="148px"
            Width="413px">
       

        <..asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <../div>
    <../form>
aspx.cs file post

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
TwitterVB2.TwitterAPI twConn = new TwitterVB2.TwitterAPI();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
//Retrieve Keys from web.config
string twitterKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
string twitterSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
string twitterOAuthToken = System.Configuration.ConfigurationManager.AppSettings["OAuthToken"];
string twitterOAuthTokenSecret = System.Configuration.ConfigurationManager.AppSettings["OAuthTokenSecret"];

//string twitterKey ="kXhmnfAxj7wcGEpKL5Flg";

//string twitterSecret ="oLEkFzdCuSNw7y8s89HxCAq5bqSwOQfDsod58pP3xc";
//string twitterOAuthToken="388768904-6oOgQN1k5O9CeDgOEDN0jWsrk1PaWCRTDVHpahRf";
//string twitterOAuthTokenSecret = "5gyVBErdjTcrxdyddx1QTY4p2gsnxvgk3na5FA8kPTE";

try
{
twConn.AuthenticateWith(twitterKey, twitterSecret, twitterOAuthToken, twitterOAuthTokenSecret);
twConn.Update(TextBox1.Text);
TextBox1.Text = "";
}
catch (Exception ex)
{
//lblError.Text = "Twitter Returned: " + ex.Message;
}
}
}

in web.configuration file

-<..configuration>
  <..appSettings>
    -->


finally add twitter.dll on bin filder

No comments: