Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Example of getting the Auth credentials for the first time by directoring the
            //user to the fitbit site to get a PIN.
            // GitHub test from Andy
            var consumerKey = "b3d888281c9b4e098c26c6d1ce4e9d57";
            var consumerSecret = "dc6f84c589c341789967b57e83084572";
            var requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            var accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            var authorizeUrl = "http://www.fitbit.com/oauth/authorize";

            var a = new Authenticator(consumerKey, consumerSecret, requestTokenUrl, accessTokenUrl, authorizeUrl);
            var url = a.GetAuthUrlToken();

            System.Diagnostics.Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = verificationCodeTextBox.Text;

            var credentials = a.GetAuthCredentialFromPin(pin);

            //If you already have your credentials stored then rather than getting the users PIN again
            //you could just start here
            var fitbit = new FitbitClient(consumerKey, consumerSecret, credentials.AuthToken, credentials.AuthTokenSecret);
            var profile = fitbit.GetUserProfile();
            Console.WriteLine("Your last weight was {0}", profile.Weight);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Authenticator authorizer = new Authenticator("a57cf7b1e3f34405a9d80b9e520c50ec", "53d618141c5c4b6f929506ef41d9611f",
                "http://api.fitbit.com/oauth/request_token",
                "http://api.fitbit.com/oauth/access_token",
                "http://www.fitbit.com/oauth/authorize");

            string url = authorizer.GetAuthUrlToken();

            Console.WriteLine("Authorization URL: " + url);

            string tempAuthToken;
            string verifier;

            Console.Write("oauth_token: ");
            tempAuthToken = Console.ReadLine();

            Console.Write("oauth_verifier: ");
            verifier = Console.ReadLine();

            AuthCredential credential = authorizer.ProcessApprovedAuthCallback(tempAuthToken, verifier);

            Console.WriteLine("access_token: " + credential.AuthToken);
            Console.WriteLine("access_secret: " + credential.AuthTokenSecret);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //Example of getting the Auth credentials for the first time by directoring the
            //user to the fitbit site to get a PIN. 
            var consumerKey = "YOUR_CONSUMER_KEY_HERE";
            var consumerSecret = "YOUR_CONSUMER_SECRET_HERE";
            var requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            var accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            var authorizeUrl = "http://www.fitbit.com/oauth/authorize";

            var a = new Authenticator(consumerKey, consumerSecret,requestTokenUrl,accessTokenUrl,authorizeUrl);
            var url = a.GetAuthUrlToken();

            Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = Console.ReadLine();

            var credentials = a.GetAuthCredentialFromPin(pin);


            //If you already have your credentials stored then rather than getting the users PIN again
            //you could just start here
            var fitbit = new FitbitClient(consumerKey, consumerSecret, credentials.AuthToken, credentials.AuthTokenSecret);
            var profile = fitbit.GetUserProfile();
            Console.WriteLine("Your last weight was {0}",profile.Weight);

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        //
        // GET: /FitbitAuth/
        // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app.
        public ActionResult Authorize()
        {
            //make sure you've set these up in Web.Config under <appSettings>:
            string ConsumerKey    = ConfigurationManager.AppSettings["FitbitConsumerKey"];
            string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];


            Fitbit.Api.Authenticator authenticator = new Fitbit.Api.Authenticator(ConsumerKey,
                                                                                  ConsumerSecret,
                                                                                  "http://api.fitbit.com/oauth/request_token",
                                                                                  "http://api.fitbit.com/oauth/access_token",
                                                                                  "http://api.fitbit.com/oauth/authorize");
            string authUrl = authenticator.GetAuthUrlToken();


            return(Redirect(authUrl));
        }
Ejemplo n.º 5
0
        private static AuthCredential GetLoginCredentials()
        {
            const string requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            const string accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            const string authorizeUrl = "http://www.fitbit.com/oauth/authorize";

            var a = new Authenticator(CONSUMER_KEY, CONSUMER_SECRET, requestTokenUrl, accessTokenUrl, authorizeUrl);
            var url = a.GetAuthUrlToken();

            Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = Console.ReadLine();

            var credentials = a.GetAuthCredentialFromPin(pin);
            return credentials;
        }
Ejemplo n.º 6
0
        //
        // GET: /FitbitAuth/
        // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app.
        public ActionResult Authorize()
        {

            //make sure you've set these up in Web.Config under <appSettings>:
            string ConsumerKey = ConfigurationManager.AppSettings["FitbitConsumerKey"];
            string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];


            Fitbit.Api.Authenticator authenticator = new Fitbit.Api.Authenticator(ConsumerKey,
                                                                                    ConsumerSecret,
                                                                                    "http://api.fitbit.com/oauth/request_token",
                                                                                    "http://api.fitbit.com/oauth/access_token",
                                                                                    "http://api.fitbit.com/oauth/authorize");
            string authUrl = authenticator.GetAuthUrlToken();


            return Redirect(authUrl);
        }
Ejemplo n.º 7
0
        private void FitBitLogin_Load(object sender, EventArgs e)
        {
            //make sure you've set these up in Web.Config under <appSettings>:
            string ConsumerKey = "84c3fd4c63f04ab88dff2ec80e7690a9";
            string ConsumerSecret = "5d8fe7b6849f4b0b8bf10261038ed836";

            Fitbit.Api.Authenticator authenticator = new Fitbit.Api.Authenticator(ConsumerKey,
                                                                                    ConsumerSecret,
                                                                                    "http://api.fitbit.com/oauth/request_token",
                                                                                    "http://api.fitbit.com/oauth/access_token",
                                                                                    "http://api.fitbit.com/oauth/authorize");
            string authUrl = authenticator.GetAuthUrlToken();

            webBrowser1.Url = new Uri(authUrl);
            //Final step. Take this authorization information and use it in the app
            dash.oauth_token = authUrl.Substring(authUrl.IndexOf("oauth_token=") +12);
        }