Ejemplo n.º 1
0
        public AccessToken GetAccessToken(string accessTokenUrl, string pin)
        {
            var accessTokenResponse = _authorizer.GetAccessToken(accessTokenUrl, _requestToken, pin);
            //accessTokenResponse.RunSynchronously();
            _accessToken = accessTokenResponse.Result.Token;

            return _accessToken;
        }
Ejemplo n.º 2
0
 public async Task<bool> GetInfo(AccessToken token, string path, bool fromForeground)
 {
     var args = new GetInfoCompletedArgs();
     if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None)
     {
         args.Canceled = true;
         OnGetInfoFinished(args);
         return true;
     }
     try
     {
         using (var client = OAuthUtility.CreateOAuthClient(ConsumerKey, ConsumerSecret, token))
         {
             if (!Cts.Token.IsCancellationRequested)
             {
                 using (Cts.Token.Register(() => client.CancelPendingRequests()))
                 {
                     if (fromForeground)
                     {
                         args.Json = await client.GetStringAsync(BaseUrl + path);
                     }
                     else
                     {
                         var info = client.GetStreamAsync(BaseUrl + path);
                         var reader = new StreamReader(info.Result);
                         args.Json = reader.ReadToEnd();
                     }
                     args.Canceled = false;
                     //args.Canceled = true;
                 }
                 OnGetInfoFinished(args);
             }
         }
     }
     catch (Exception)
     {
         CancelTask();
         args.Canceled = true;
         OnGetInfoFinished(args);
     }
     return true;
 }
Ejemplo n.º 3
0
		public void AddToken(TwitterApplication application, AccessToken token)
		{
			Guard.ArgumentNull(application, "application");
			Guard.ArgumentNull(token, "token");

			// 同じアプリケーションのトークンが登録されていないかどうかを確認
			var duplicate = this.Tokens.SingleOrDefault(t => t.Application.Id == application.Id);
			if (duplicate == null)
			{
				this.Tokens.Add(new TwitterToken(application, token));
			}
			else
			{
				duplicate.ChangeToken(token);
			}
		}
Ejemplo n.º 4
0
		public TwitterAccount(TwitterApplication application, AccessToken token)
			: this(EnumerableEx.Return(new TwitterToken(application, token))) { }
Ejemplo n.º 5
0
 public static HttpClient CreateOAuthClient(HttpMessageHandler innerHandler, string consumerKey, string consumerSecret, AccessToken accessToken, IEnumerable<KeyValuePair<string, string>> optionalOAuthHeaderParameters = null)
 {
     return new HttpClient(new OAuthMessageHandler(innerHandler, consumerKey, consumerSecret, accessToken, optionalOAuthHeaderParameters));
 }
Ejemplo n.º 6
0
 public async Task<bool> GetInfo(AccessToken token, KeyValuePair valuePair, bool fromForeground)
 {
     if (valuePair.content != null && valuePair.name != null)
         return await GetInfo(token, "sim_balance.json" + "?" + string.Format(Parameter, valuePair.name, HttpUtility.UrlEncode((string)valuePair.content)), fromForeground);
     return false;
 }
Ejemplo n.º 7
0
 public VikingsClient(string consumerKey, string consumerSecret, AccessToken accessToken)
 {
     this.consumerKey = consumerKey;
     this.consumerSecret = consumerSecret;
     this.accessToken = accessToken;
 }
Ejemplo n.º 8
0
 public async Task<bool> GetInfo(AccessToken token, string path, KeyValuePair[] valuePair, CancellationTokenSource cts)
 {
     var builder = new StringBuilder();
     builder.Append(string.Format("?{0}={1}", valuePair[0].Name, HttpUtility.UrlEncode(((string)valuePair[0].Content))));
     for (var i = 1; i < valuePair.Length; i++)
     {
         builder.Append(string.Format("&{0}={1}", valuePair[i].Name, valuePair[i].Content));
     }
     return await GetInfo(token, path + builder, cts);
 }
Ejemplo n.º 9
0
 public async Task<bool> GetInfo(AccessToken token, string location, KeyValuePair valuePair, CancellationTokenSource cts)
 {
     if (valuePair.Content != null && valuePair.Name != null)
         return await GetInfo(token, location + "?" + string.Format(Parameter, valuePair.Name, HttpUtility.UrlEncode((string)valuePair.Content)), cts);
     return false;
 }
Ejemplo n.º 10
0
 public static void Save(AccessToken token)
 {
     File.WriteAllText(path, DynamicJson.Serialize(token));
 }
Ejemplo n.º 11
0
		public void ChangeToken(AccessToken token)
		{
			this.TokenKey = token.Key;
			this.TokenSecret = token.Secret;
		}
Ejemplo n.º 12
0
		public TwitterToken(TwitterApplication application, AccessToken token)
			: this(application, token.Key, token.Secret) { }
Ejemplo n.º 13
0
 public static HttpClient CreateOAuthClient(string consumerKey, string consumerSecret, AccessToken accessToken, IEnumerable <KeyValuePair <string, string> > optionalOAuthHeaderParameters = null)
 {
     return(new HttpClient(new OAuthMessageHandler(consumerKey, consumerSecret, accessToken, optionalOAuthHeaderParameters)));
 }