1

So I'm working with the Twitter API. My code looks like this:

        public ActionResult AuthorizeTwitter()
    {            
        Response.Redirect(GetRequestToken());
        return View();
    }

    private string GetRequestToken()
    {
        var twitter = new Twitter(consumer, consumerSecret, oauth_token, oauth_token_secret);
        twitter.BaseURI = requestUrl;
        var result = twitter.GetRequest("http://localhost:60707/Twitter/GetAccessToken");

        string[] resultArray = result.Split('&');
        twitter.RequestToken = resultArray[0].Split('=')[1];
        twitter.RequestTokenSecret = resultArray[1].Split('=')[1];

        var requestToken = Session["oauth_token"] = resultArray[0].Split('=')[1];            
        Session["oauth_secret"] = resultArray[1].Split('=')[1];

        string redirect = authorizeUrl + requestToken;
        return (redirect);
    }

    public ActionResult GetAccessToken()
    {

        string verifier = Request.Params["oauth_verifier"];
        string token = Request.Params["oauth_token"];
        string secret = Session["oauth_secret"].ToString();
        .....
    }

I set the Session["oauth_secret"] in my GetRequestToken method and when I debug I see it fine.

However, when I get down to GetAccessToken, that value is no longer there and Session is null. Why is this?

Also, a related question, should I be keeping these values in Session?

Are there any problems with doing this and is there a better way to do it?

Tharif
  • 13,794
  • 9
  • 55
  • 77
ygetarts
  • 923
  • 3
  • 14
  • 29

1 Answers1

0

Did you check about your accessToken of your twitter expired? I think it has a limited time and after that you must get it again. Think about automation get accessToken in amount of time.

ThanhND25
  • 86
  • 4