public override void Execute() { try { base.Execute(); } catch (GDataRequestException re) { HttpWebResponse webResponse = re.Response as HttpWebResponse; if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized) { Tracing.TraceMsg("Access token might have expired, refreshing."); Reset(); try { OAuthUtil.RefreshAccessToken(this.factory.Parameters); } catch (WebException e) { Tracing.TraceMsg("Failed to refresh access token: " + e.StackTrace); throw re; } base.Execute(); } else { throw; } } }
private void EnsureOAuthCredentials(HttpWebRequest request) { string oauthHeader = OAuthUtil.GenerateHeader( request.RequestUri, this.ConsumerKey, this.ConsumerSecret, this.Token, this.TokenSecret, request.Method); request.Headers.Add(oauthHeader); }
/// <summary> /// sets up the correct credentials for this call. /// </summary> protected override void EnsureCredentials() { HttpWebRequest http = this.Request as HttpWebRequest; if (string.IsNullOrEmpty(this.factory.ConsumerKey) || string.IsNullOrEmpty(this.factory.ConsumerSecret)) { throw new GDataRequestException("ConsumerKey and ConsumerSecret must be provided to use GOAuthRequestFactory"); } string oauthHeader = OAuthUtil.GenerateHeader( http.RequestUri, this.factory.ConsumerKey, this.factory.ConsumerSecret, this.factory.Token, this.factory.TokenSecret, http.Method); this.Request.Headers.Remove("Authorization"); // needed? this.Request.Headers.Add(oauthHeader); }