2015-07-01 2 views
1

Я использую this python library из Google, но я не могу понять, что использовать для аргумента 'body'. Есть ли пример тела, из которого я могу рисовать, чтобы создать dict, чтобы этот инструмент понадобился?Google подходит данные через библиотеки api google python

Вот код, который я использую:

flow = client.flow_from_clientsecrets(
    workLaptop, 
    scope='https://www.googleapis.com/auth/fitness.activity.read', 
    redirect_uri='oauth:code:from:somehwere') 

auth_uri = flow.step1_get_authorize_url() 
webbrowser.open_new(auth_uri) 

auth_code = "a;ldskjfa;lsdkfja;ldsfkja;lsdkfjaldgha;" 

credentials = flow.step2_exchange(auth_code) 
http_auth = credentials.authorize(httplib2.Http()) 

service = discovery.build('fitness', 'v1',http_auth) 
fitData = service.users().dataset().aggregate(userId='me',body=body).execute() 

Это все хорошо до той части, где мне нужно, чтобы определить тело. Вот тело, которое я пытаюсь:

body = { 
    "aggregateBy": [ 
     { 
     "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", 
     "dataTypeName": "com.google.step_count.delta" 
     }, 
    ], 
    "bucketByActivitySegment": { 
     "minDurationMillis": "A String", # Only activity segments of duration longer than this is used 
    }, 
    "endTimeMillis": "1435269600000000000", 
    "bucketBySession": { 
     "minDurationMillis": "10", # Only sessions of duration longer than this is used 
    }, 
    "bucketByActivityType": { 
     "minDurationMillis": "10", # Only activity segments of duration longer than this is used 
    }, 
    "startTimeMillis": "1435183200000000000", # required time range 
    "bucketByTime": { # apparently oneof is not supported by reduced_nano_proto 
     "durationMillis": "10", 
    }, 
} 

Что не так с моим телом? Вот код ошибки: https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?alt=json вернулся «Внутренняя ошибка»>

Вот пример объекта в Исследователь API: enter image description here

+0

Вот ссылка для проводника API: https://developers.google.com/apis-explorer/?hl=ru_RU/p}/fitness/v1/fitness. user.dataset.aggregate? userId = me Это позволит вам «обрабатывать» тело dict с помощью инструмента, но я не могу найти комбинацию, которая будет возвращать значения. – billmanH

ответ

0

Хотя я не на 100% не знаком с API Google для Google Fit, в первую очередь возникают определенные проблемы с запросом тела вашего JSON.

Например:

body = { 
    "aggregateBy": [ 
     { 
     "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", 
     "dataTypeName": "com.google.step_count.delta" 
     }, 
    ], 
    "bucketByActivitySegment": { 
     "minDurationMillis": "A String", # Only activity segments of duration longer than this is used 
    }, 
    "endTimeMillis": "1435269600000000000", 
    "bucketBySession": { 
     "minDurationMillis": "10", # Only sessions of duration longer than this is used 
    }, 
    "bucketByActivityType": { 
     "minDurationMillis": "10", # Only activity segments of duration longer than this is used 
    }, 
    "startTimeMillis": "1435183200000000000", # required time range 
    "bucketByTime": { # apparently oneof is not supported by reduced_nano_proto 
     "durationMillis": "10", 
    }, 
} 

Если быть на самом деле это;

body = { 
    "aggregateBy": [ 
     { 
     "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", 
     "dataTypeName": "com.google.step_count.delta" 
     } 
    ], 
    "bucketByActivitySegment": { 
     "minDurationMillis": "A String" # Only activity segments of duration longer than this is used 
    }, 
    "endTimeMillis": "1435269600000000000", 
    "bucketBySession": { 
     "minDurationMillis": "10" # Only sessions of duration longer than this is used 
    }, 
    "bucketByActivityType": { 
     "minDurationMillis": "10" # Only activity segments of duration longer than this is used 
    }, 
    "startTimeMillis": "1435183200000000000", # required time range 
    "bucketByTime": { # apparently oneof is not supported by reduced_nano_proto 
     "durationMillis": "10" 
    } 
} 

JSON на основе Остальные услуги действительно неумолима для использования дополнительной запятой, где они не должны быть, это делает строку не-jsonable, которая приведет к 500 неудаче. Попробуйте в первую очередь;)

+0

, похоже, не так просто. Все еще получил 500 ошибок. :( – billmanH

+0

Что мне действительно нужно, это пример конфигурации, которая работает. Я удивлен, что Google ничего не выдал. – billmanH

+1

'' minDurationMillis ":" String "' выглядит недействительным –

0

Не специалист сам, но я играю с API в течение нескольких дней. Вот образец с моей игровой площадки OAuth.

Sample response

Из того, что я понимаю, ваши «endTimeMillis»: «1435269600000000000» не правильно определяется как это в наносекунд. Чтобы оно было в милли, измените его на «1435269600000»

Смежные вопросы