1

float 値を持つ Point を に保存しようとしていますfitness.body。値を取得することは問題ではありませんが、新しいポイントを保存すると問題が発生します403. No permission to modify data for this source.

derived:com.google.weight:com.google.android.gms:merge_weightポイントを見つけて値を読み取り、データを挿入するためにDataSetId を使用していraw:com.google.weight:com.google.android.apps.fitness:user_inputます。

.

Ruby と を使用したワークフローは次のgoogle-api-ruby-clientとおりです。

require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'pry'

# Initialize the client.
client = Google::APIClient.new(
  :application_name => 'Example Ruby application',
  :application_version => '1.0.0'
)

fitness = client.discovered_api('fitness')

# Load client secrets from your client_secrets.json.
client_secrets = Google::APIClient::ClientSecrets.load

flow = Google::APIClient::InstalledAppFlow.new(
  :client_id => client_secrets.client_id,
  :client_secret => client_secrets.client_secret,
  :scope => ['https://www.googleapis.com/auth/fitness.body.write',
             'https://www.googleapis.com/auth/fitness.activity.write',
             'https://www.googleapis.com/auth/fitness.location.write']
)
client.authorization = flow.authorize

新しいデータ ポイントの形成:

dataSourceId = 'raw:com.google.weight:com.google.android.apps.fitness:user_input'

startTime = (Time.now-1).to_i # 1 Second ago
endTime = (Time.now).to_i

metadata = {
  dataSourceId: dataSourceId,
  maxEndTimeNs: "#{startTime}000000000", # Faking nanoseconds with tailing zeros
  minStartTimeNs: "#{endTime}000000000",
  point: [
    {
      endTimeNanos: "#{endTime}000000000",
      startTimeNanos: "#{startTime}000000000",
      value: [
        { fpVal: 80 }
      ]
    }
  ]
}

ポイントを保存しようとしています:

result = client.execute(
  :api_method => fitness.users.data_sources.datasets.patch,
  :body_object => metadata,
  :parameters => {
    'userId' => "me",
    'dataSourceId' => dataSourceId,
    'datasetId' => "#{Time.now.to_i-1}000000000-#{(Time.now).to_i}000000000"
  }
)

そして、私が以前に示したように、私は得ています403. No permission to modify data for this source

#<Google::APIClient::Schema::Fitness::V1::Dataset:0x3fe78c258f60 DATA:{"error"=>{"er
rors"=>[{"domain"=>"global", "reason"=>"forbidden", "message"=>"No permission to modif
y data for this source."}], "code"=>403, "message"=>"No permission to modify data for
this source."}}>

スコープ内の必要なすべてのアクセス許可を選択したと思います。私はポイントをfitness.bodyの両方のアクセス可能なdatasetidに送信しようとしました。

ここで何か間違ったことをしている場合はお知らせください。

ありがとうございました!

4

2 に答える 2

0

Authorization ヘッダーを追加してみてください。

result = client.execute(
  :api_method => fitness.users.data_sources.datasets.patch,
  :headers => {'Authorization' => 'Bearer YOUR_AUTH_TOKEN'},
  :body_object => metadata,
  :parameters => {
    'userId' => "me",
    'dataSourceId' => dataSourceId,
    'datasetId' => "#{Time.now.to_i-1}000000000-#{(Time.now).to_i}000000000"
  }
)
于 2015-02-12T21:48:02.110 に答える