使用 rails 在没有 oauth 的情况下访问 google 驱动器电子表格的内容

Access content of a google drive spreadsheet without oauth with rails

我正在尝试使用 rails 创建一个 Web 应用程序,它可以访问 google 驱动器电子表格并且:

  1. 列出内容[只读]
  2. 可以add/modify值

有没有不使用 oauth 的方法?我目前有一个使用 oauth 的解决方案,但我希望至少拥有不使用 oauth 的只读访问权限,如果可能的话还可以修改它们。

编辑:我目前正在使用 google 驱动器 ruby gem https://github.com/gimite/google-drive-ruby

提前致谢

作为只读,您可以使用我在此处回答的 HTML 解决方案:

解决方案终于很简单了。 问题是我没有在我使用的 gem(Google 驱动器 Ruby)的文档中看到有一种名为使用用户名和密码登录的方法。最后的解决方案是这样的:

class StockController < ApplicationController
  before_action :login

  def index 
    respond_to do |format|
      format.json{ render json: document.rows}
    end
  end

  def login
    @session = GoogleDrive.login(ENV["GDRIVE_USERNAME"], ENV["GDRIVE_PASSWORD"])
  end

  def document
    @session.spreadsheet_by_key("key_of_the_spreadsheet").worksheets[0]
  end
end