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); RequestToken token = a.GetRequestToken(); var url = a.GenerateAuthUrlFromRequestToken(token, false); Process.Start(url); Console.WriteLine("Enter the verification code from the website"); var pin = Console.ReadLine(); var credentials = a.GetAuthCredentialFromPin(pin, token); //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(); }
static AuthCredential Authenticate() { 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); RequestToken token = a.GetRequestToken(); var url = a.GenerateAuthUrlFromRequestToken(token, false); Process.Start(url); Console.WriteLine("Enter the verification code from the website"); var pin = Console.ReadLine(); var credentials = a.GetAuthCredentialFromPin(pin, token); return credentials; }
// // 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"); RequestToken token = authenticator.GetRequestToken(); Session.Add("FitbitRequestTokenSecret", token.Secret.ToString()); //store this somehow, like in Session as we'll need it after the Callback() action //note: at this point the RequestToken object only has the Token and Secret properties supplied. Verifier happens later. string authUrl = authenticator.GenerateAuthUrlFromRequestToken(token, true); return(Redirect(authUrl)); }
// // 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"); RequestToken token = authenticator.GetRequestToken(); Session.Add("FitbitRequestTokenSecret", token.Secret.ToString()); //store this somehow, like in Session as we'll need it after the Callback() action //note: at this point the RequestToken object only has the Token and Secret properties supplied. Verifier happens later. string authUrl = authenticator.GenerateAuthUrlFromRequestToken(token, true); return Redirect(authUrl); }