Not Checling Authentication


#1

Hi,
When I first visit to My Tweeter Page it check Authentication and Authorization perfect but wen I sign our to twitter, Next Time it does not checks for authorization and redirect me to MyTwitter Page. I am storing my access token in session.


#2

What is the exact error you’re seeing? Can you share code you’re using?


#3

I’m a newbie for twitter, seem i click all and to collect information , so probably i did some mistake, sorry about that., and thank you for reminding me


#4

In Login Page :
protected void Page_Load(object sender, EventArgs e)
{
string ConsumerKey = ConfigurationManager.AppSettings[“ConsumerKey”];
string ConsumerSecret = ConfigurationManager.AppSettings[“ConsumerSecret”];

        OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret);
        if (Session["AccessToken"] != null)
        {
            Response.Redirect("~/Twitter/CallBack.aspx");
        }
        else
        {
            Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqToken.Token), true);
        }
    }

And in call back page :

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString[“oauth_token”].ToString() != null)
{

                TwitterBasePage.Instance().CreateCachedAccessToken(Request.QueryString["oauth_token"].ToString());
                Response.Redirect("TwitterConfirmation.aspx");

            }
        }

When Redirect to TwitterPost Page

protected void btnPost_Click(object sender, EventArgs e)
{
try
{
if (Session[“AccessToken”] != null)
{
TwitterStatus obj = TwitterStatus.Update(TwitterBasePage.Instance().GetCachedAccessToken(), lblPost.Text);
if (obj == null)
{
TwitterBasePage.Instance().DisplayAlert(“Invalid Request”);
}
else
{
TwitterBasePage.Instance().DisplayAlert(“valid Request”);
info.Text = “You have posted sucessfully”;
info.Visible = true;
data_post.Visible = false;
div_confirm.Visible = true;
}
//txtTweet.Text = “”;
//this.DisplayAlert(“Tweet posted!”);
}
else
{
TwitterBasePage.Instance().DisplayAlert(“Bad Request”);
//Response.Redirect(TwitterBasePage.Instance().GetTwitterAuthorizationUrl());
//TwitterStatus.Update(TwitterBasePage.Instance().GetCachedAccessToken(), lblPost.Text);
// txtTweet.Text = “”;
// this.DisplayAlert(“Tweet posted!”);
}

        }
        catch (Exception ex)
        {
            throw ex;
        }   
    }

#5

It doesn’t look like you’re ever upgrading your request token to an access token, and it doesn’t look like you’re ever getting the oauth token secret.

It’s going to be much easier to use a library for this kind of thing. Twitterizer (http://www.twitterizer.net/) documents this case pretty well: http://www.twitterizer.net/documentation/html/008da98c-7349-46d6-b09e-af9f8906eb47.htm