Пример #1
0
        public void Start()
        {
            var clientIdentifier = "11df6ee71f2fa9e5799164c20c8bc099";
            var clientSecret     = "57862a3d8bc915d728566216575697b3";
            var tokenEndpoint    = "https://api.fitbit.com/oauth2/token";
            var clientID         = "229XX2";

            //  START THE AUTH PROCESS - provide needed info for auth process
            Authenticator auth = new Authenticator(clientID, clientIdentifier, clientSecret, tokenEndpoint);

            auth.Authenticate();

            //  server functions
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Console.WriteLine("Server stared!");

                try
                {
                    while (_listener.IsListening)
                    {
                        ThreadPool.QueueUserWorkItem((c) =>
                        {
                            var context = c as HttpListenerContext;

                            try
                            {
                                string responderString = _responderMethod(context.Request);

                                //  Get auth code from request URL to server
                                Uri requestUri = context.Request.Url;
                                var code       = HttpUtility.ParseQueryString(requestUri.Query).Get("code");

                                byte[] buf = Encoding.UTF8.GetBytes(responderString);

                                context.Response.ContentLength64 = buf.Length;
                                context.Response.OutputStream.Write(buf, 0, buf.Length);

                                //  Exchange code for accessToken
                                string accessToken = auth.AccessToken(code);

                                //  Send request for FitBit info - define what info you want
                                FitBitRequest req = new FitBitRequest(accessToken);
                                //string requestScope = "profile";


                                //req.SendRequest(requestScope);
                                req.SendRequest();
                            }

                            //Suppress any exceptions
                            catch { }

                            finally
                            {
                                context.Response.OutputStream.Close();
                            }
                        }, _listener.GetContext());
                    }
                }
                //Suppress any exceptions
                catch { }
            });
        }
Пример #2
0
        public void Start()
        {

            var clientIdentifier = "11df6ee71f2fa9e5799164c20c8bc099";
            var clientSecret = "57862a3d8bc915d728566216575697b3";
            var tokenEndpoint = "https://api.fitbit.com/oauth2/token";
            var clientID = "229XX2";

            //  START THE AUTH PROCESS - provide needed info for auth process
            Authenticator auth = new Authenticator(clientID, clientIdentifier, clientSecret, tokenEndpoint);
            auth.Authenticate();

            //  server functions
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Console.WriteLine("Server stared!");

                try
                {
                    while (_listener.IsListening)
                    {
                        ThreadPool.QueueUserWorkItem((c) =>
                        {
                            var context = c as HttpListenerContext;

                            try
                            {
                                string responderString = _responderMethod(context.Request);

                                //  Get auth code from request URL to server
                                Uri requestUri = context.Request.Url;
                                var code = HttpUtility.ParseQueryString(requestUri.Query).Get("code");

                                byte[] buf = Encoding.UTF8.GetBytes(responderString);

                                context.Response.ContentLength64 = buf.Length;
                                context.Response.OutputStream.Write(buf, 0, buf.Length);

                                //  Exchange code for accessToken
                                string accessToken = auth.AccessToken(code);

                                //  Send request for FitBit info - define what info you want
                                FitBitRequest req = new FitBitRequest(accessToken);
                                //string requestScope = "profile";


                                //req.SendRequest(requestScope);
                                req.SendRequest();
                            }

                            //Suppress any exceptions
                            catch { }

                            finally
                            {
                                context.Response.OutputStream.Close();
                            }

                        }, _listener.GetContext());
                    }
                }
                //Suppress any exceptions
                catch { }

            });
        }