【问题标题】:Fitbit account Integration in AndroidAndroid 中的 Fitbit 帐户集成
【发布时间】:2013-01-19 03:53:48
【问题描述】:

我正在开发一个与医学相关的应用程序,我必须在我的应用程序中实现 FitBit 设备。

我正在关注 FitBit 开发人员工具,但我无法集成它,如果我在没有 FitBit 库的情况下手动执行此操作,我将无法在身份验证后返回我的应用程序。

我的代码在下面-

    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();
            }

        }

在获得 authToken 后,我打开了一个网页,但无法返回 再次在我的应用程序上。

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

【问题讨论】:

标签: android callback fitbit


【解决方案1】:

我终于得到了自己问题的答案-

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();
        }

然后——

    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);

编辑: 你可以从这里下载邮政编码-

http://www.androidhub4you.com/2013/11/fitbit-integration-in-android-login.html

https://github.com/manishsri01/FitbitIntegration

【讨论】:

  • 您是否设法使整个过程自动化?用户登录后如何访问生成的 PIN?
  • @M.V.登录后,我读取了 URL 响应并对其进行了子串化。 authToken = webServiceInfo.substring(12, 44); Log.e("Auth token:", "Webservice:" + authToken);
  • 当然......通过它你得到令牌......所以你可以调用FitBit登录页面和授权......之后你应该收到验证器而不是请求访问令牌......当我这样做时。 . 我在屏幕上看到的只是 PIN,我不希望用户复制/粘贴 PIN :)
  • @AnasAzeem 请下载邮政编码。如果对您有帮助,请放弃对我的回答和问题的投票。
  • @M.V.请下载邮政编码..如果对您有帮助,请放弃对我的回答和问题的投票。
【解决方案2】:

我使用这个和其他各种来源创建了一个使用 Scribe OAuth 库的示例“从 Android 连接到 Fitbit”项目。项目是 GitHub 上的here。这是一项正在进行的工作,但我确实有它为适当的用户进行身份验证并获取一些数据。

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 2016-01-13
    • 2014-01-14
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多