やりたいこと
phpからスプレットシートへの書き込み、読み込みを行いたい。
環境
Conoha VPSのアプリケーションテンプレートLEMP(PHP)を利用し
composerにて必要ライブラリをインストールしています。
インストール時のcomposer.jsonは
json
1{ 2 "require": { 3 "google/cloud": "^0.13.0", 4 "google/apiclient": "^2.0" 5 } 6}
Google APIsの認証情報
text
1サービスアカウントキー
になります。
現状書いているphpのコード
php
1<?php 2error_reporting(E_ALL); 3ini_set('display_errors',1); 4date_default_timezone_set('Asia/Tokyo'); 5 6require 'vendor/autoload.php'; 7 8define('SPREADSHEET_ID', getenv('XXXXXXXXXXXX(シートID)XXXXXXXXXXXXX')); 9 10$client = new Google_Client(); 11$client->setAuthConfig('XXXXXX(ダウンロードされたファイル名)XXXXXXX.json'); 12$client->addScope(Google_Service_Sheets::SPREADSHEETS); 13$client->setApplicationName('test'); 14 15$service = new Google_Service_Sheets($client); 16 17$response = $service->spreadsheets_values->get(SPREADSHEET_ID, 'シート1!A1:D5'); 18foreach ($response->getValues() as $index => $cols) { 19 sprintf('#%d >> "%s"', $index+1, implode('", "', $cols)).PHP_EOL; 20} 21?>
表示されているエラー
html
1Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ 2 "error": { 3 "code": 404, 4 "message": "Requested entity was not found.", 5 "errors": [ 6 { 7 "message": "Requested entity was not found.", 8 "domain": "global", 9 "reason": "notFound" 10 } 11 ], 12 "status": "NOT_FOUND" 13 } 14} 15' in /usr/local/openresty/nginx/html/vendor/google/apiclient/src/Google/Http/REST.php:118 16Stack trace: 17#0 /usr/local/openresty/nginx/html/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') 18#1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') 19#2 /usr/local/openresty/nginx/html/vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Array) 20#3 /usr/local/openresty/nginx/html/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() 21#4 /us in /usr/local/openresty/nginx/html/vendor/google/apiclient/src/Google/Http/REST.php on line 118
試したこと
1、ロリポップのサーバーからconohaへ
2、利用する認証情報のキーをp12で
3、OAuth クライアントIDを利用
どうしたら良いでしょうか?、わかる方よろしくお願いいたします。
あなたの回答
tips
プレビュー