gpt4 book ai didi

android - Android 中的 Fitbit 账户集成

转载 作者:太空狗 更新时间:2023-10-29 16:43:03 27 4
gpt4 key购买 nike

我正在开发一个与医学相关的应用程序,我必须在我的应用程序中实现 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");
}

最佳答案

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

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

此外,您可以从我的 github 帐户下载邮政编码- https://github.com/manishsri01/FitbitIntegration

关于android - Android 中的 Fitbit 账户集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14686906/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com