Пример #1
0
        private void Refresh()
        {
            var client = CreateClient(TokenUrl, this.clientId);

            client.Authenticator = new HttpBasicAuthenticator(this.clientId, string.Empty);
            var request = new RestRequest("api/v1/access_token", Method.POST);

            request.AddQueryParameter("api_type", "json");
            request.AddParameter("grant_type", "refresh_token");
            request.AddParameter("refresh_token", this.apikey.refresh);
            var result = client.Execute(request);

            if (result.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Token refresh request failed. \n {0}", result.Content));
            }

            var parsed_result = JsonConvert.DeserializeObject <Token>(result.Content);

            this.apikey = new APIKey(parsed_result.access_token, this.apikey.refresh, parsed_result.expires_in);
            this.APIKeyUpdated.Invoke(this.apikey);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedditOAuthClient"/> class.
 /// </summary>
 /// <param name="clientId">App id of the reddit app.</param>
 /// <param name="apikey">API key data.</param>
 public RedditOAuthClient(string clientId, APIKey apikey)
 {
     this.apikey   = apikey;
     this.client   = CreateClient(OauthUrl, clientId);
     this.clientId = clientId;
 }
Пример #3
0
 public SpecializedRedditClient(APIKey apikey, string clientId)
     : base(clientId, apikey)
 {
 }
Пример #4
0
 private static void Reddit_APIKeyUpdated(APIKey apikey)
 {
     Log.Info("APIKey updated, saving to file.");
     File.WriteAllText(CfgPath, JsonConvert.SerializeObject(apikey));
 }