Android Wear上的Google Fit API出现问题 [英] Issue with Google Fit API on Android Wear

查看:213
本文介绍了Android Wear上的Google Fit API出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Google Fit API应用到我的android可穿戴应用程序中。
我在GoogleFitAPI在线步骤中注册了一个OAuth ID。



尝试连接时,我收到了无效的帐户错误。 b
$ b

我是否需要在开发人员api控制台中启用免费试用版,或者是否存在导致此问题的其他问题?

  mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.API)
.addScope(Fitness.SCOPE_ACTIVITY_READ)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();


解决方案

实际上,适用API在Android Wear设备上可用。但是您仍然需要进行一次初始设置(步骤5 )配对的手持设备。一旦登录并在手机上显示同意屏幕,就可以从手表访问A​​PI。建议使用 MessageAPI ,以避免在所需信息同步到手表之前尝试连接到API。



请注意,如果您选择访问您只能从手表获取数据(数据从手表同步到手机和云,但不会返回手表)。

另一种解决方案是从手机获取健身数据并将其发送到手表(再次使用MessageAPI)。

编辑:
自Google Play Services 7.3.0您还可以使用 Fitness.HistoryApi.readDailyTotal() if你只是想获得每日总价值。这不需要任何验证,但也只会给你本地设备的数据。


I'm trying to implement the Google Fit API into my android wearable application. I have followed the GoogleFitAPI online steps with registering for an OAuth ID.

When trying to connect, I get an invalid account error.

Do I need to enable the free trial within the developer api console, or is there another issue that is causing this?

mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.API)
            .addScope(Fitness.SCOPE_ACTIVITY_READ)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

解决方案

Actually the Fit API is available on Android Wear devices. But you still have to do the initial setup (Step 5) one time on a paired handheld device. Once you've logged in and displayed the consent screen on the phone, you can access the API from the watch. A recommendation would be to send the selected user account to the watch using the MessageAPI to avoid trying to connect to the API before the required information has been synced to the watch.

Please note that if you chose to access the API from the watch you will ONLY get data collected by the watch (data is synced from the watch to the phone and to the cloud, but not back to the watch).

An alternative solution is to fetch the fitness data from the phone and send it to the watch (again using the MessageAPI).

EDIT: As of Google Play Services 7.3.0 you can also use Fitness.HistoryApi.readDailyTotal() if you just want to get the daily total value. This doesn't require any authentication, but will also only give you data from the local device.

这篇关于Android Wear上的Google Fit API出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆