Using google fit api from a backend server

前端 未结 1 1627
梦毁少年i
梦毁少年i 2021-01-28 02:01

I\'m writing an android application which needs to read user\'s fitness data (steps, calories, etc) from a back end server. this server will read the data and push notifications

相关标签:
1条回答
  • 2021-01-28 02:08

    In case anyone needs this, there is javadoc available here. And here is a simple example of a batch request for the user's height and weight from the backend server:

    GoogleCredential credential = new GoogleCredential().setAccessToken(activeUser.getAccessToken());
    
    Fitness fitness = new Fitness.Builder(new NetHttpTransport(), 
                                          JacksonFactory.getDefaultInstance(), 
                                          credential)
            .setApplicationName("MyApp")
            .build();
    
    BatchRequest batchRequest = new BatchRequest(new NetHttpTransport(), credential);
    fitness.users()
            .dataSources()
            .datasets()
            .get("me", "derived:com.google.weight:com.google.android.gms:merge_weight",
                            String.format("0-%d", System.nanoTime()))
            .queue(batchRequest, new WeightRequestCallback(activeUser));
    
    fitness.users()
            .dataSources()
            .datasets()
            .get("me", "derived:com.google.height:com.google.android.gms:merge_height",
                    String.format("0-%d", System.nanoTime()))
            .queue(batchRequest, new HeightRequestCallback(activeUser));
    
    
    batchRequest.execute();
    

    HeightRequestCallback and WeightRequestCallback extend JsonBatchCallback<Dataset>

    0 讨论(0)
提交回复
热议问题