简体   繁体   中英

Google fit api steps returns 0 for some users

I am developing an android app that will count steps for users. I am using google fitness api to do so. I have enabled fitness api in my developer console and link my app to that. When I install the app in my device, it works perfectly showing me my steps. However if I install it on another device, it does not show any steps(steps returned are 0). Do you have any suggestions on what might be the problem? The email I declared when I enabled the fitness api in my developer console is the same with the one in my device that it works. Should I declare something else?

Google Fitness API is not connected to the account you use for the developer console. The console certificates are connected to the app, hence why you specify the SHA-1 keystore and package name when getting the OAuth 2.0 certificate. I tried this with a colleague and the OAuth certificate he generated on another account for our app worked when I used it as well.

Perhaps the problem is that you're signed in to the wrong account on your second device. Google Fitness data is connected to your Google account and should be accessible cross-devices and platforms, but if you're not in the right account you obviously won't be able to fetch your fitness history.

As Lovis said, I believe counting steps is opt-in, so you'd have to login to something that subscribes to your Google Fit steps account to start recording step counts on a second device. However, you should still be able to read from another device without opting in to the Recording API.

Edit: In addition to what I said above, if you're sure you're connected to the same account you might see what this SO question says: to use DataReadRequest.Builder.enableServerQueries() as documented here .

Enable querying the Google Fit server to fetch query results, in case the local store doesn't have data for the full requested time range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM