Esempio n. 1
0
        public OAuthToken GetAccessToken(Uri baseUri, string consumerKey, string consumerSecret, OAuthToken requestToken)
        {
            try
            {
                var uri = new Uri(baseUri, "oauth/access_token");

                uri = SignRequest(uri, consumerKey, consumerSecret, requestToken);

                var request = (HttpWebRequest)WebRequest.Create(uri);
                request.Method = WebRequestMethods.Http.Get;

                var response = request.GetResponse();
                var reader = new StreamReader(response.GetResponseStream());
                var accessToken = reader.ReadToEnd();

                var parts = accessToken.Split('&');
                var token = parts[1].Substring(parts[1].IndexOf('=') + 1);
                var secret = parts[0].Substring(parts[0].IndexOf('=') + 1);

                return new OAuthToken(token, secret);
            }

            catch
            {
                System.Windows.Forms.MessageBox.Show("You must sign-in and give permission to the app to continue.");
                return null;
            }
        }
Esempio n. 2
0
        public String TestUploadFiles()
        {
            Console.WriteLine("Attempting to get access token before uploading the file");
            //Your access token: 6on3pwn3smj94m4
            //Your access secret: tj4429nmp6nc9af
            var accessToken = new OAuthToken("6on3pwn3smj94m4", "tj4429nmp6nc9af");

            var api = new DropboxApi(ConsumerKey, ConsumerSecret, accessToken);

            var file = api.UploadFile("dropbox", "TargetFileName.ext", @"test.txt");

            var account = api.GetAccountInfo();
            Console.WriteLine(account.DisplayName);
            Console.WriteLine(account.Email);

            var total = account.Quota.Total / (1024 * 1024);
            var used = (account.Quota.Normal + account.Quota.Shared) / (1024 * 1024);

            Console.WriteLine(String.Format("Dropbox: {0}/{1} Mb used", used, total));

            Console.WriteLine(string.Format("{0} uploaded.", file.Path));

            Console.WriteLine();
            Console.WriteLine("Done. Press any key to continue...");
            Console.Read();

            return String.Format("{0}/{1} Mb used", used, total);
        }
Esempio n. 3
0
 public Uri GetAuthorizeUri(Uri baseUri, OAuthToken requestToken, Uri callbackUrl)
 {
     var queryString = String.Format("oauth_token={0}", requestToken.Token);
     if (callbackUrl != null)
     {
         queryString = String.Format("{0}&&oauth_callback={1}", queryString, callbackUrl);
     }
     var authorizeUri = String.Format("{0}{1}?{2}", baseUri, "oauth/authorize", queryString);
     return new Uri(authorizeUri);
 }
        public OAuthToken GetAccessToken(Uri baseUri, string consumerKey, string consumerSecret, OAuthToken requestToken)
        {
            var uri = new Uri(baseUri, "oauth/access_token");

            uri = SignRequest(uri, consumerKey, consumerSecret, requestToken);

            var request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = WebRequestMethods.Http.Get;

            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            var accessToken = reader.ReadToEnd();

            var parts = accessToken.Split('&');
            var token = parts[1].Substring(parts[1].IndexOf('=') + 1);
            var secret = parts[0].Substring(parts[0].IndexOf('=') + 1);

            return new OAuthToken(token, secret);
        }
Esempio n. 5
0
        public Account getDropboxAccount()
        {
            Console.WriteLine("Attempting to get access token before uploading the file");
            //Your access token: 6on3pwn3smj94m4
            //Your access secret: tj4429nmp6nc9af
            var accessToken = new OAuthToken("6on3pwn3smj94m4", "tj4429nmp6nc9af");

            var api = new DropboxApi(ConsumerKey, ConsumerSecret, accessToken);

            var account = api.GetAccountInfo();
            Console.WriteLine(account.DisplayName);
            Console.WriteLine(account.Email);

            var total = account.Quota.Total / (1024 * 1024);
            var used = (account.Quota.Normal + account.Quota.Shared) / (1024 * 1024);

            Console.WriteLine(String.Format("Dropbox: {0}/{1} Mb used", used, total));

            return account;
        }
Esempio n. 6
0
        public static void Main()
        {
            // Uncomment the following line or manually provide a valid token so that you
            // don't have to go through the authorization process each time.
            // var accessToken = GetAccessToken();

            //Your access token: 6on3pwn3smj94m4
            //Your access secret: tj4429nmp6nc9af
            var accessToken = new OAuthToken("6on3pwn3smj94m4", "tj4429nmp6nc9af");

            var api = new DropboxApi(ConsumerKey, ConsumerSecret, accessToken);

            var file = api.UploadFile("dropbox", "TargetFileName.ext", @"test.txt");

            Console.WriteLine(string.Format("{0} uploaded.", file.Path));

            Console.WriteLine();
            Console.WriteLine("Done. Press any key to continue...");
            Console.ReadKey();
        }
        public Uri SignRequest(Uri uri, string consumerKey, string consumerSecret, OAuthToken token, string httpMethod)
        {
            var nonce = _oAuthBase.GenerateNonce();
            var timestamp = _oAuthBase.GenerateTimeStamp();
            string parameters;
            string normalizedUrl;

            string requestToken = token == null ? String.Empty : token.Token;
            string tokenSecret = token == null ? String.Empty : token.Secret;

            var signature = _oAuthBase.GenerateSignature(
                uri, consumerKey, consumerSecret,
                requestToken, tokenSecret, httpMethod, timestamp,
                nonce, OAuthBase.SignatureTypes.HMACSHA1,
                out normalizedUrl, out parameters);

            var requestUri = String.Format("{0}?{1}&oauth_signature={2}",
                normalizedUrl, parameters, HttpUtility.UrlEncode(signature));

            return new Uri(requestUri);
        }
 public Uri SignRequest(Uri uri, string consumerKey, string consumerSecret, OAuthToken token = null)
 {
     return SignRequest(uri, consumerKey, consumerSecret, token, "GET");
 }
 public Uri GetAuthorizeUri(Uri baseUri, OAuthToken requestToken)
 {
     var queryString = String.Format("oauth_token={0}", requestToken.Token);
     var authorizeUri = String.Format("{0}{1}?{2}", baseUri, "oauth/authorize", queryString);
     return new Uri(authorizeUri);
 }
Esempio n. 10
0
 public static void Connect()
 {
     try
     {
         strDropBoxConnected = "Yes";
         accessToken = GetAccessToken();
     }
     catch (Exception ex)
     {
         strDropBoxConnected = "No";
         MessageBox.Show("Connecting DropBox failed!");
     }
 }
Esempio n. 11
0
 public Uri GetAuthorizeUri(Uri baseUri, OAuthToken requestToken)
 {
     return GetAuthorizeUri(baseUri, requestToken, null);
 }
Esempio n. 12
0
 public Uri SignRequest(Uri uri, string consumerKey, string consumerSecret, OAuthToken token = null)
 {
     return(SignRequest(uri, consumerKey, consumerSecret, token, "GET"));
 }
Esempio n. 13
0
        public OAuthToken GetAccessToken(Uri baseUri, string consumerKey, string consumerSecret, OAuthToken requestToken)
        {
            var uri = new Uri(baseUri, "oauth/access_token");

            uri = SignRequest(uri, consumerKey, consumerSecret, requestToken);

            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method = WebRequestMethods.Http.Get;

            var response    = request.GetResponse();
            var reader      = new StreamReader(response.GetResponseStream());
            var accessToken = reader.ReadToEnd();

            var parts  = accessToken.Split('&');
            var token  = parts[1].Substring(parts[1].IndexOf('=') + 1);
            var secret = parts[0].Substring(parts[0].IndexOf('=') + 1);

            //Console.WriteLine(token + "\n" + secret);
            return(new OAuthToken(token, secret));
        }