configjson
1{ 2 "client_id": "xxxxxxxxxxxxxxxxx.apps.googleusercontent.com", 3 "client_secret": "xxxxxxxxxxxxxxxxxx" 4 }
ruby
1 2 3require "google_drive" 4 5# config.jsonを読み込んでセッションを確立 6session = GoogleDrive::Session.from_config("config.json") 7 8# スプレッドシートをURLで取得 9sp = session.spreadsheet_by_url("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxx/edit#gid=0") 10 11# "シート1"という名前のワークシートを取得 12ws = sp.worksheet_by_title("シート1") 13 14# セルを指定して値を更新 インデックスの基準は1 15ws[2, 1] = "foo" # セルA2 16ws[2, 2] = "bar" # セルB2 17 18# saveで変更を保存、実際にスプレッドシートに反映させる 19ws.save
上記のrubyファイルを実行するとコマンドプロンプトに以下のような表示がされます。
cmd
11. Open this page: 2https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drivexxxhttps://spreadsheets.google.com/feeds/ 3 42. Enter the authorization code shown in the page:
1に記載されたurlにアクセスすると「google-drive-ruby が Google アカウントへのアクセスをリクエストしています」というページが表示され、許可ボタンをクリックすると「このコードをコピーし、アプリケーションに切り替えて貼り付けてください」というメッセージの下にコードが表示されているのでコマンドプロンプトにコピペすると
cmd
1`connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (Faraday::SSLError)
というエラーが出て、調べてみるとSSL証明書が古いのが原因ということがわかったのでcacert.pemをダウンロードしRubyのディレクトリに保存し、システム環境変数に新規でSSL_CERT_FILEを登録しパスを通しました。その後、リトライしたのですがエラーのままで困っています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。