In following sample I can post messages on twitter , using Twitter New API , getting messages from database
and post in a defined interval. this is very good tool for advertisement.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Net;
using System.IO;
using oAuthExample;
using System.Threading;
public partial class autoposttest : System.Web.UI.Page
{
string txtMSGtweet;
string txttweet = "dut yaar dimag mat kharab kar.. ..";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyLabel.Text = System.DateTime.Now.ToString();
}
if (Session["Usrid"] == null)
{
// Response.Redirect("login.aspx");
}
else
{
labuser.Text = "Hi " + Session["Usrid"].ToString();
}
getmsg();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = " : " + DateTime.Now.ToLongTimeString();
getmsg();
}
public void getmsg()
{
string url = "";
string xml = "";
oAuthTwitter oAuth = new oAuthTwitter();
if (Request["oauth_token"] == null)
{
oAuth.CallBackUrl = "http://127.0.0.1/twitterpost/autoposttest.aspx";
Response.Redirect(oAuth.AuthorizationLinkGet());
}
else
{
oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
//Response.Write(oAuth.TokenSecret.ToString());
//Response.End();
if (oAuth.TokenSecret.Length > 0)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
char YNtxt = 'N';
string strSQL = "select top 5 * from TwitAutoMsg where TwitYN= '" + YNtxt + "'";
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
myConnection.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (myReader.Read())
{
txtMSGtweet = myReader["TwitMsg"].ToString();
// Response.Write(txtMSGtweet + "<br>");
string strTwitID = myReader["TwitID"].ToString();
updatedata(strTwitID);
//SubmitUserMsg();
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode(txtMSGtweet.ToString()));
apiResponse.InnerHtml = Server.HtmlEncode(xml);
Thread.Sleep(12000);
Label4.Text = "<br>Last Message Posted - " + txtMSGtweet.ToString();
}
myReader.Close();
myConnection.Close();
}
}
}
public void updatedata(string strTwitID1)
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
int strTwitIDInt = Convert.ToInt32(strTwitID1);
char YNtxtu = 'Y';
strSQL = "Update TwitAutoMsg set TwitYN='" + YNtxtu + "' where TwitID=" + strTwitID1;
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.CommandType = CommandType.Text;
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
private string ConnectionString
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["VISLI_DVConnectionString"].ConnectionString;
return connectionString;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//Response.Write("asas");
Label1.Text = " : " + DateTime.Now.ToLongTimeString();
// getmsg();
}
}
No comments:
Post a Comment