1

Google のこの python ライブラリを使用していますが、'body' 引数に何を使用すればよいかわかりません。このツールが必要とする dict を作成するために描画できる例の本文はありますか?

私が使用しているコードは次のとおりです。

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 Explorer でのオブジェクトの例を次に示します。 ここに画像の説明を入力

4

2 に答える 2

0

私は Google Fit 用の Google API を 100% 信頼しているわけではありませんが、最初の例では、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 エラーが発生します。最初に試してみてください;)

于 2015-07-07T03:04:59.540 に答える
0

私自身は専門家ではありませんが、API で何日も遊んでいます。私の OAuth プレイグラウンドのサンプルを次に示します。

サンプル応答

私が理解していることから、あなたの "endTimeMillis": "1435269600000000000" はナノ秒単位であるため、正しく定義されていません。ミリ単位にするには、「1435269600000」に変更します

于 2016-05-22T15:43:03.037 に答える