protected void Page_Load(object sender, EventArgs e) { auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken); if (!Page.IsPostBack) { // try to complete a pending authorization in case there is one. string accessToken = auth.CompleteAuthorize(); if (accessToken != null) { // Store the access token in session state so we can get at it across page refreshes. // In a real app, you'd want to associate this access token with the user that is // logged into your app at this point. InMemoryTokenManager.AccessToken = accessToken; // Clear away the OAuth message so that users can refresh the page without problems. Response.Redirect(Page.Request.Path); } } if (string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) || string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret)) { // The user needs to set up the web.config file to include Twitter consumer key and secret. PrivateDataMultiView.SetActiveView(SetupTwitterConsumer); } else if (auth.CachedCredentialsAvailable) { auth.SignOn(); // acquire the screen name, and ensure the access token is still valid. screenNameLabel.Text = auth.ScreenName; PrivateDataMultiView.SetActiveView(ViewPrivateUpdates); updateBox.Focus(); } else { PrivateDataMultiView.SetActiveView(AuthorizeTwitter); } twitterCtx = auth.CachedCredentialsAvailable ? new TwitterContext(auth) : new TwitterContext(); var tweets = from tweet in twitterCtx.Status where tweet.Type == (auth.CachedCredentialsAvailable ? StatusType.Friends : StatusType.Public) select tweet; TwitterListView.DataSource = tweets; TwitterListView.DataBind(); // demonstrate serialization var serializableUser = (from user in twitterCtx.User where user.Type == UserType.Show && user.ScreenName == "JoeMayo" select user) .FirstOrDefault(); // if you have ASP.NET state server turned on // this will still work because User is serializable Session["SerializableUser"] = serializableUser; }
protected void Page_Load(object sender, EventArgs e) { auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken); if (string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) || string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret) || !auth.CachedCredentialsAvailable) { // Authorization occurs only on the home page. Response.Redirect("~/"); } updateBox.Focus(); }
protected void Page_Load(object sender, EventArgs e) { auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken); if (!string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) && !string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret)) { AuthMultiView.ActiveViewIndex = 1; if (!IsPostBack) { if (auth.CompleteAuthenticate()) { AuthMultiView.SetActiveView(SignedInView); screenNameLabel.Text = auth.ScreenName; } } } }