はじめに
こんにちは、イメージ・マジックのもあいです。GoogleのSpreadsheet APIを仕事で使用したので備忘録として残しておきます。
プロジェクトの作成
Googleアカウントでログインしておいて、Google Cloud コンソール の APIライブラリページ にアクセスし、プロジェクトの選択をクリックします
新しいプロジェクトをクリックします

プロジェクト名を入力して作成をクリック

しばらくするとプロジェクトが作成されます。
APIを有効にする
プロジェクトを作成した後、プロジェクトを選択すると下記の様になるので、Drive APIとSpreadsheet APIを有効にします。
Google Drive APIを選択して、有効にするをクリックします

Google Spreadsheet APIを選択して、有効にするをクリックします

認証情報の作成
Google Drive APIとGoogle Spreadsheet APIを有効にしたら認証情報を作成をクリックします

認証情報の作成は下記の様に選択をして次へボタンをクリックします

サービスアカウントIDを入力して作成して続行ボタンをクリック。サービスアカウントが作成できましたと表示されるので、完了ボタンをクリックします。

これでサービスアカウントが作成できました。
左ペインの認証情報をクリックして、サービスアカウント欄のサービスアカウントをクリックします。

キーをクリックします

鍵を追加をクリックし、新しい鍵を作成をクリックします

JSONを選択して作成をクリックします

jsonファイルがダウンロードされました。今後このファイルと画面に表示されているサービスアカウントのメールアドレス(testsample@testsample-398107.iam.gserviceaccount.com)を保存しておいてください。Driveでのファイルオーナーになります。