{"id":3281,"date":"2021-02-01T14:44:05","date_gmt":"2021-02-01T05:44:05","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=3281"},"modified":"2024-01-15T23:51:45","modified_gmt":"2024-01-15T14:51:45","slug":"post-3281","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3281","title":{"rendered":"Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3068PHP\u3092\u9023\u643a\u3055\u305b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u30fb\u8ffd\u8a18\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3068PHP\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u9023\u643a\u3055\u305b\u305f\u3044\u3068\u3044\u3046\u6848\u4ef6\u3092\u305f\u307e\u306b\u898b\u304b\u3051\u308b\u3002\u304a\u554f\u3044\u5408\u308f\u305b\u30da\u30fc\u30b8\u7b49\u306e\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u30c7\u30fc\u30bf\u767b\u9332\u30fb\u9001\u4fe1\u3057\u305f\u969b\u306bMySQL\u3068\u306f\u5225\u306b\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u5074\u306b\u3082\u8ffd\u8a18\u3057\u3066\u3044\u304d\u305f\u3044\u3001\u3068\u3044\u3063\u305f\u5185\u5bb9\u304c\u591a\u3044\u3002\u4ee5\u4e0b\u306b\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>\u4ee5\u4e0b\u3088\u308a\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u65b0\u898f\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/www.google.com\/intl\/ja_jp\/sheets\/about\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.google.com\/intl\/ja_jp\/sheets\/about\/<\/a><\/p>\n<p>\u4f5c\u6210\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u306eURL\u304c\u767a\u884c\u3055\u308c\u300cxxxxxxx\u300d\u306e\u90e8\u5206\u304c\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8ID\u3068\u306a\u308b\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">https:\/\/docs.google.com\/spreadsheets\/d\/xxxxxxxxxxxxxxx\/edit#gid=0<\/pre>\n<p>&nbsp;<\/p>\n<h2>Google Cloud Platform\u3067\u8af8\u3005\u8a2d\u5b9a\u3059\u308b<\/h2>\n<p>\u4ee5\u4e0bGoogle Cloud Platform\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/console.cloud.google.com\" target=\"_blank\" rel=\"noopener\">https:\/\/console.cloud.google.com<\/a><\/p>\n<p>\u6b21\u306b<a href=\"https:\/\/console.cloud.google.com\/apis\/library\/sheets.googleapis.com\" target=\"_blank\" rel=\"noopener\">Google Sheets API<\/a>\u3092\u6709\u52b9\u5316\u3057\u3001\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u8a8d\u8a3c\u60c5\u5831\u3092\u4f5c\u6210\u3059\u308b\u3068JSON\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u308b\u306e\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002\u307e\u305fJSON\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u300cclient_email\u300d\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u8a18\u5165\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u5074\u3067\u5171\u6709\u3057\u3066\u304a\u304f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>PHP\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4f5c\u6210<\/h2>\n<p>PHP\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8a2d\u7f6e\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4ee5\u4e0b\u30b3\u30de\u30f3\u30c9\u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5c0e\u5165\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">curl -sS https:\/\/getcomposer.org\/installer | php\r\nphp composer.phar require google\/apiclient:\"^2.0\"<\/pre>\n<h3>\u30c7\u30fc\u30bf\u3092\u8ffd\u8a18\u3059\u308b\u5834\u5408<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nrequire __DIR__. '\/vendor\/autoload.php';\r\n\r\n\/\/\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\r\n$keyFile = __DIR__. \"\/credentials.json\";\r\n\r\n\/\/ \u30a2\u30ab\u30a6\u30f3\u30c8\u8a8d\u8a3c\u60c5\u5831\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\r\n$client = new Google_Client();\r\n$client-&gt;setAuthConfig($keyFile);\r\n\r\n\/\/\u4efb\u610f\u540d\r\n$client-&gt;setApplicationName(\"Sheet API TEST\");\r\n\r\n\/\/\u30b5\u30fc\u30d3\u30b9\u306e\u6a29\u9650\u30b9\u30b3\u30fc\u30d7\r\n$scopes = [Google_Service_Sheets::SPREADSHEETS];\r\n$client-&gt;setScopes($scopes);\r\n\r\n\/\/\u30b7\u30fc\u30c8\u60c5\u5831\u3092\u64cd\u4f5c\u3059\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\r\n$sheet = new Google_Service_Sheets($client);\r\n\r\n\/\/\u5bfe\u8c61\u306e\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306eID\u3092\u6307\u5b9a\r\n$sheet_id = 'xxxxxxxx';\r\n\r\n\/\/\u30b7\u30fc\u30c8\u540d\r\n$sheet_name = '\u30b7\u30fc\u30c81';\r\n\r\n\/\/\u4fdd\u5b58\u3059\u308b\u30c7\u30fc\u30bf\r\n$values = [\r\n    ['\u5c71\u75302', '\u82b1\u5b502'],\r\n    ['\u5c71\u75302', '\u592a\u67172']\r\n];\r\n\r\n\/\/\u30c7\u30fc\u30bf\u64cd\u4f5c\u9818\u57df\u3092\u8a2d\u5b9a\r\n$body = new Google_Service_Sheets_ValueRange([\r\n    'values' =&gt; $values,\r\n]);\r\n\r\n\/\/\u8ffd\u8a18\r\n$response = $sheet-&gt;spreadsheets_values-&gt;append(\r\n    $sheet_id,\r\n    $sheet_name,\r\n    $body,\r\n    [\"valueInputOption\" =&gt; 'USER_ENTERED']\r\n);\r\n\r\nvar_export($response-&gt;getUpdates());<\/pre>\n<h3>\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nrequire __DIR__. '\/vendor\/autoload.php';\r\n\r\n\/\/\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u30d5\u30a1\u30a4\u30eb\r\n$keyFile = __DIR__. \"\/credentials.json\";\r\n\r\n\/\/ \u30a2\u30ab\u30a6\u30f3\u30c8\u8a8d\u8a3c\u60c5\u5831\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\r\n$client = new Google_Client();\r\n$client-&gt;setAuthConfig($keyFile);\r\n\r\n\/\/\u4efb\u610f\u540d\r\n$client-&gt;setApplicationName(\"Sheet API TEST\");\r\n\r\n\/\/\u30b5\u30fc\u30d3\u30b9\u306e\u6a29\u9650\u30b9\u30b3\u30fc\u30d7\r\n$scopes = [Google_Service_Sheets::SPREADSHEETS];\r\n$client-&gt;setScopes($scopes);\r\n\r\n\/\/\u30b7\u30fc\u30c8\u60c5\u5831\u3092\u64cd\u4f5c\u3059\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\r\n$sheet = new Google_Service_Sheets($client);\r\n\r\n\/\/\u5bfe\u8c61\u306e\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306eID\u3092\u6307\u5b9a\r\n$sheet_id = 'xxxxxxxx';\r\n\r\n\/\/\u30b7\u30fc\u30c8\u540d\r\n$sheet_name = '\u30b7\u30fc\u30c81';\r\n\r\n\/\/\u53d6\u5f97\u7bc4\u56f2\u3092\u6307\u5b9a\uff08data\u30b7\u30fc\u30c8\u306eA1\u301cB8\uff09\r\n$range = $sheet_name . '!A1:B8';\r\n$response = $sheet-&gt;spreadsheets_values-&gt;get($sheet_id, $range);\r\n$values = $response-&gt;getValues();\/\/\u5e30\u3063\u3066\u304d\u305fresponse\u304b\u3089\u5024\u3092\u53d6\u5f97\r\n \r\nprint_r($values);<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u3044\u3064\u3082\u601d\u3046\u304cGoogle Cloud Platform\u306e\u64cd\u4f5c\u304c\u9762\u5012\u3002\u3069\u3053\u306b\u4f55\u304c\u3042\u308b\u306e\u304b\u5206\u304b\u308a\u3065\u3089\u3044\u6c17\u304c\u3059\u308b\u3002\u30d7\u30ed\u30b0\u30e9\u30e0\u3088\u308aGCP\u306e\u8a2d\u5b9a\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u305f\u3002<\/p>\n<p>\u5c1a\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u9023\u643a\u306b\u3064\u3044\u3066\u306f\u3068\u308a\u3042\u3048\u305a\u8ffd\u8a18\u304c\u30e1\u30a4\u30f3\u306b\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u306f\u5bfe\u5fdc\u3067\u304d\u305d\u3046\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"http:\/\/bashalog.c-brains.jp\/19\/04\/12-101500.php\" target=\"_blank\" rel=\"noopener\">http:\/\/bashalog.c-brains.jp\/19\/04\/12-101500.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3068PHP\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u9023\u643a\u3055\u305b\u305f\u3044\u3068\u3044\u3046\u6848\u4ef6\u3092\u305f\u307e\u306b\u898b ... <\/p>\n","protected":false},"author":1,"featured_media":3294,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,72,70],"tags":[],"class_list":["post-3281","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-google-apps-script","category-google"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3281"}],"version-history":[{"count":0,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3281\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/3294"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}