Fitbit account Integration in Android

Issue

I am working on an application which is related to medical science, where I have to implement FitBit device with my application.

I am following FitBit developer tools for it but I am unable to integrate it and if I am doing it manually without FitBit library I am unable to back on my application after authentication.

My code is below-

    private void login() {

            try {

                HttpResponse response = null;
                HttpParams httpParameters = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
                HttpConnectionParams.setSoTimeout(httpParameters, 20000);
                HttpClient client = new DefaultHttpClient(httpParameters);

                HttpGet request = new HttpGet(
                        "http://api.fitbit.com/oauth/request_token?oauth_consumer_key=7af733f021f649bcac32f6f7a4fe2e9a&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1358921319&oauth_nonce=456236281&oauth_callback=http://www.androidhub4you.com/&oauth_version=1.0&oauth_token=5cefb18d2a80073520211f03f8d75321&oauth_signature=QdVUzMvT6tveGyoPu%2BEevzvo07s%3D");
                response = client.execute(request);

                BufferedReader rd = new BufferedReader(new InputStreamReader(
                        response.getEntity().getContent()));

                String webServiceInfo = "";
                while ((webServiceInfo = rd.readLine()) != null) {
                    Log.e("****Step 1***", "Webservice: " + webServiceInfo);
                    authToken = webServiceInfo.substring(12, 44);
                    Log.e("Auth token:", "Webservice: " + authToken);

                }

            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

        }

And after getting authToken I open a web page but I am unable to back
on my application again.

      private void openURL() {
                webView.loadUrl("https://www.fitbit.com/oauth/authorize?oauth_token="
                        + authToken + "&display=touch");
            }

Solution

Finally I got answer of my own question-

try {

            HttpResponse response = null;
            HttpParams httpParameters = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
            HttpConnectionParams.setSoTimeout(httpParameters, 20000);
            HttpClient client = new DefaultHttpClient(httpParameters);

            HttpGet request = new HttpGet(
                    "http://api.fitbit.com/oauth/request_token?oauth_consumer_key=7af733f021f649bcac32f6f7a4fe2e9a&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1358921319&oauth_nonce=456236281&oauth_callback=http://www.androidhub4you.com/&oauth_version=1.0&oauth_token=5cefb18d2a80073520211f03f8d75321&oauth_signature=QdVUzMvT6tveGyoPu%2BEevzvo07s%3D");
            response = client.execute(request);

            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));

            String webServiceInfo = "";
            while ((webServiceInfo = rd.readLine()) != null) {
                Log.e("****Step 1***", "Webservice: " + webServiceInfo);
                authToken = webServiceInfo.substring(12, 44);
                Log.e("Auth token:", "Webservice: " + authToken);

            }

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

And after that-

    String fitUrl = "https://www.fitbit.com/oauth/authorize?oauth_token="
                    + authToken +"&display=touch";
            webView.loadUrl(fitUrl);
 Intent intent = new Intent(FitBitActivity.this, DashboardActivity.class);
            pActivity.finishChildActivity(intent);

Answered By – Manish Srivastava

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published