表格API v4返回503不可用

时间:2017-04-04 01:06:31

标签: google-sheets google-api google-sheets-api google-api-ruby-client

我使用Google API Ruby client做了4件事:

  1. 访问我的驱动器
  2. 制作新的电子表格
  3. 更新电子表格中的单元格
  4. 从同一电子表格中获取包含计算结果的单元格
  5. 我能够成功实现上面列出的前3个项目,但在尝试获取单元格时出现503错误。如果我 运行#batch_update_values方法,我可以从电子表格中获取单元格。只有当两个函数按顺序调用时才会出现错误,但在单独调用时仍然有效。

    在我的服务中:

    data = [list of ValueRange Objects]
    request_body = Google::Apis::SheetsV4::BatchUpdateValuesRequest.new
    request_body.value_input_option = "user_entered";
    request_body.data = data;
    
    # this works
    @sheets_client.batch_update_values(working_copy.id, request_body)
    
    
    # this does not work even with retries set
    range = "Sheet2!A3:BN23"
    response = @sheets_client.get_spreadsheet_values(working_copy.id, range, value_render_option: "UNFORMATTED_VALUE", date_time_render_option: "SERIAL_NUMBER")
    

    确切的错误是:

    {"error": {
    "cause": null,
    "status_code": 503,
    "header": {
      "Vary": "Referer",
      "Content-Type": "application/json; charset=UTF-8",
      "Content-Encoding": "gzip",
      "Date": "Tue, 04 Apr 2017 00:42:21 GMT",
      "Server": "ESF",
      "Cache-Control": "private",
      "X-Xss-Protection": "1; mode=block",
      "X-Frame-Options": "SAMEORIGIN",
      "Alt-Svc": "quic=\":443\"; ma=2592000; v=\"37,36,35\"",
      "Transfer-Encoding": "chunked"
    },
    "body": "{\n  \"error\": {\n    \"code\": 503,\n    \"message\": \"The service is currently unavailable.\",\n    \"errors\": [\n      {\n        \"message\": \"The service is currently unavailable.\",\n        \"domain\": \"global\",\n        \"reason\": \"backendError\"\n      }\n    ],\n    \"status\": \"UNAVAILABLE\"\n  }\n}\n"
    

    } }

    更新:

    def generate_value_range_objects(data)
      value_range_objects = []
      data.each do |range, value|
        value_range_objects << Google::Apis::SheetsV4::ValueRange.new(major_dimension: "ROWS", values: [[value]], range: range)
      end
      value_range_objects
    end
    
    d = Hash.new
    d["Sheet1!B5"] = "# Address"
    d["Sheet1!B6"] = "# City/Town"
    d["Sheet1!B7"] = "# County"
    d["Sheet1!B8"] = "# State"
    d["Sheet1!B9"] = "# Zip"
    
    d["Sheet1!B11"] = "# Year Built"
    d["Sheet1!B12"] = "# Year Gut Renovated"
    
    d["Sheet1!B14"] =  "# Number of Residential Units"
    d["Sheet1!B15"] =  "# Number of Commercial Units"
    d["Sheet1!B17"] =  "# Number of Occupied Units Mo. X"
    d["Sheet1!B18"] =  "# Number of Occupied Units Mo. X"
    d["Sheet1!B19"] =  "# Number of Occupied Units Mo. X"
    
    # Operating Numbers
    # Something in here causing issue
    d["Sheet1!B22"] = "# Income "
    d["Sheet1!B23"] = "# Less Concessions"
    d["Sheet1!B24"] = "# Vacancy"
    d["Sheet1!B27"] = "# Income "
    d["Sheet1!B28"] = "# Plus Income Other"
    d["Sheet1!B35"] = "# Expense"
    d["Sheet1!B36"] = "# Expense"
    d["Sheet1!B37"] = "# Expense"
    d["Sheet1!B38"] = "# Expense"
    d["Sheet1!B39"] = "# Expense"
    d["Sheet1!B40"] = "# Expense"
    d["Sheet1!B41"] = "# Expense"
    
    
    data = generate_value_range_objects(d)
    request_body = Google::Apis::SheetsV4::BatchUpdateValuesRequest.new
    request_body.value_input_option = "user_entered";
    request_body.data = data;
    
    @sheets_client.batch_update_values(working_copy.id, request_body)
    

0 个答案:

没有答案