ルビー起こっていない:私はシートを持っている5.0.0GoogleシートV4 APIのRuby - 列のセルの値を更新しようとしているが、更新が
:2.3.1
のRails A、B、C、Dはシート内の列名を表し、1、2、3は行番号を表します。
私はおよそhere、そこから前述のスクリプトを書いている私は、細胞B2とB3で、私は次のコードを使用しています更新するための値を更新しようとしています:
spreadsheet_id = "<My Private Spreadsheet ID>"
range = 'Sheet1!B2:B3'
value_range_object = {
"majorDimension"=>"COLUMNS",
"values"=>[
[9, 18] # B2 should be updated with value 9 and B3 should be updated with value 18
]
}
service = Google::Apis::SheetsV4::SheetsService.new
service.authorization = authorization
update_res = service.update_spreadsheet_value(spreadsheet_id, range, value_range_object, value_input_option: 'USER_ENTERED')
puts ">>>>>>>>>> update_res: #{update_res.inspect}"
しかし、それは
>>>>>>>>>> update_res: #<Google::Apis::SheetsV4::UpdateValuesResponse:0x000000068acc70 @updated_range="Sheet1!B2", @spreadsheet_id="<My Private Spreadsheet ID>">
を印刷されますとなり、シートに更新は行われません。更新は、応答の成功、次のようなものが応答して、私はそこに自分のコードに欠けているか、間違っているものは間違いで、これは取得していますことを比較
{
"spreadsheetId": spreadsheetId,
"updatedRange": "Sheet1!B1:D5",
"updatedRows": 3,
"updatedColumns": 2,
"updatedCells": 6,
}
を受信する必要がありますされdocumentationを1として
適用される更新を妨害する。
私の問題を克服して私の目標を達成するためのガイダンスを得ることができますか?
更新
私は私のサービスとそれを共有し、私はGoogleドライブ上の新鮮な新しい白紙を作成し、この一環としてhttps://developers.google.com/sheets/samples/writing#write_a_single_range
で与えられた例以下のわずかに異なるアプローチでこれを試してみましたアカウントを更新し、次のコードで更新しようとしました:
require 'google/apis/sheets_v4'
ENV["GOOGLE_ACCOUNT_TYPE"] = 'service_account'
ENV["GOOGLE_CLIENT_EMAIL"] = '<client_email_from_downloaded_json_here>'
ENV["GOOGLE_PRIVATE_KEY"] = "<private_key_from_downloaded_json_here>"
SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS
authorization = Google::Auth.get_application_default(SCOPE)
# Initialize the API
service = Google::Apis::SheetsV4::SheetsService.new
service.authorization = authorization
spreadsheet_id = '<MY SPREADSHEET ID HERE>'
sheet_name = 'Sheet1'
range = "Sheet1!A1:D5"
value_range_object = {
"majorDimension" => "ROWS",
"values" => [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "30/20/2016"],
["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
]
}
update_res = service.update_spreadsheet_value(spreadsheet_id, range, value_range_object, value_input_option: 'USER_ENTERED')
puts ">>>>>>>>>> update_res: #{update_res.inspect}"
しかし、それは変なこともありません。次の応答があります。
>>>>>>>>>> update_res: #<Google::Apis::SheetsV4::UpdateValuesResponse:0x00000006540348 @updated_range="Sheet1!A1", @spreadsheet_id="MY SPREADSHEET ID HERE">
となり、コードを実行するとシートも空白になります。
誰でもこれを見て、何が起こっているかについてコメントできますか?