{"id":4605,"date":"2024-02-27T12:29:53","date_gmt":"2024-02-27T03:29:53","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=4605"},"modified":"2024-02-15T13:48:21","modified_gmt":"2024-02-15T04:48:21","slug":"post-4605","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/4605","title":{"rendered":"GAS\u3068Google\u30ab\u30ec\u30f3\u30c0\u3092\u9023\u643a\u3057\u66a6\u901a\u308a\u3067\u306f\u306a\u3044\u5e97\u4f11\u65e5\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u5c0f\u58f2\u5e97\u7b49\u306e\u30b5\u30a4\u30c8\u3067\u55b6\u696d\u65e5\u30ab\u30ec\u30f3\u30c0\u30fc\u307f\u305f\u3044\u306a\u3082\u306e\u3092\u8868\u793a\u3055\u305b\u308b\u969b\u306b\u4eca\u307e\u3067\u306fPHP\u3067\u7ba1\u7406\u753b\u9762\u3092\u4f5c\u6210\u3057\u3001\u305d\u3061\u3089\u3067\u5e97\u4f11\u65e5\u3092\u767b\u9332\u3057\u3066\u3082\u3089\u3044\u3001\u305d\u306e\u30c7\u30fc\u30bf\u3092\u30ab\u30ec\u30f3\u30c0\u30fc\u306b\u53cd\u6620\u3055\u305b\u308b\u3068\u3044\u3046\u5f62\u3092\u53d6\u3063\u3066\u3044\u305f\u3002\u3053\u306e\u5f62\u3067\u3082\u4e0d\u6e80\u306f\u7121\u3044\u3093\u3060\u3051\u3069GAS\u3068Google\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u4f7f\u3048\u3070\u3082\u3063\u3068\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u306b\u601d\u3063\u305f\u306e\u3067\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4eca\u56de\u3084\u308a\u305f\u3044\u3053\u3068<\/h2>\n<p>Google\u30ab\u30ec\u30f3\u30c0\u30fc\u306b\u5e97\u4f11\u65e5\u3092\u767b\u9332\u2192GAS\u3067\u4f5c\u3063\u305fAPI\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u5e97\u4f11\u65e5\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\u3067\u304d\u308b\u3068\u3044\u3046\u4e00\u9023\u306e\u6d41\u308c\u3092\u4f5c\u308a\u305f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Google\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u6e96\u5099<\/h2>\n<p>Google\u30ab\u30ec\u30f3\u30c0\u30fc\u2192\u8a2d\u5b9a\u2192\u30de\u30a4\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u8a2d\u5b9a\u2192\u5e97\u4f11\u65e5\u7528\u306e\u30ab\u30ec\u30f3\u30c0\u30fc\u3092\u6307\u5b9a\u3068\u9032\u3080\u3068\u30ab\u30ec\u30f3\u30c0\u30fcID\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u30e1\u30e2\u3063\u3066\u304a\u304f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u6e96\u5099<\/h2>\n<p>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u30b7\u30fc\u30c8\u540d\u3092\u300choliday\u300d\u306b\u5909\u66f4\u3057\u3066\u304a\u304f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>GAS(API\u5074)<\/h2>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function setHoliday(){\r\n\r\n    \/\/\u958b\u59cb\u5e74\u6708\u65e5\u3068\u7d42\u4e86\u5e74\u6708\u65e5\u306e\u6307\u5b9a\r\n    const now = new Date();\r\n    const start = now.getFullYear() + '-01-01';\r\n    const end = (now.getFullYear() + 1) + '-12-31';\r\n\r\n    \/\/Google\u30ab\u30ec\u30f3\u30c0\u30fc\u304b\u3089\u795d\u65e5\u53d6\u5f97\r\n    const calendar = CalendarApp.getCalendarById('\u3010\u30ab\u30ec\u30f3\u30c0\u30fcID\u3011').getEvents(new Date(start), new Date(end));\r\n\r\n    \/\/\u795d\u65e5\u30c7\u30fc\u30bf\u3092\u6574\u5f62\u3057\u3066\u914d\u5217\u306b\u683c\u7d0d\r\n    const result = [];\r\n    for( var i = 0; i &lt; calendar.length; i++ ){\r\n        result[i] = [\r\n            Utilities.formatDate(calendar[i].getStartTime(), 'JST', 'yyyy-MM-dd'), \r\n            calendar[i].getTitle()\r\n        ];\r\n    }\r\n\r\n    console.log(result);\r\n    return false;\r\n\r\n    \/\/\u6b63\u5e38\u306b\u30c7\u30fc\u30bf\u304c\u53d6\u5f97\u3067\u304d\u305f\u5834\u5408\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306b\u66f8\u304d\u8fbc\u307f\r\n    if( result.length ){\r\n\r\n        \/\/\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u8aad\u307f\u8fbc\u307f\r\n        const sheet = SpreadsheetApp.getActiveSpreadsheet();\r\n\r\n        \/\/\u30b7\u30fc\u30c8\u3092\u6307\u5b9a\r\n        const holidaySheet = sheet.getSheetByName('holiday');\r\n\r\n        \/\/\u30b7\u30fc\u30c8\u306b\u307e\u3068\u3081\u3066\u66f8\u304d\u8fbc\u307f\r\n        holidaySheet.getRange(1, 1, result.length, result[0].length).setValues(result);\r\n    }\r\n}\r\n\r\n\/\/\u795d\u65e5\u30c7\u30fc\u30bf\u3092JSON\u51fa\u529b\r\nfunction getHoliday(){\r\n\r\n    \/\/\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306e\u8aad\u307f\u8fbc\u307f\r\n    const sheet = SpreadsheetApp.getActiveSpreadsheet();\r\n\r\n    \/\/\u30b7\u30fc\u30c8\u3092\u6307\u5b9a\r\n    const holidaySheet = sheet.getSheetByName('holiday');\r\n\r\n    \/\/\u30b7\u30fc\u30c8\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\r\n    const holidaySheetVal = holidaySheet.getDataRange().getValues();\r\n\r\n    \/\/\u5e74\u6708\u65e5\u306e\u6574\u5f62\r\n    for( let i = 0; i &lt; holidaySheetVal.length; i++ ){\r\n        holidaySheetVal[i][0] = Utilities.formatDate(holidaySheetVal[i][0], 'JST', 'yyyy-MM-dd');\r\n    }\r\n\r\n    \/\/\u30c7\u30fc\u30bf\u3092JSON\u5316\r\n    const payload = JSON.stringify(holidaySheetVal);\r\n\r\n    \/\/Textoutput\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\r\n    const output = ContentService.createTextOutput();\r\n\r\n    \/\/Mime Type\u3092JSON\u306b\u8a2d\u5b9a\r\n    output.setMimeType(ContentService.MimeType.JSON);\r\n\r\n    \/\/\u30c7\u30fc\u30bf\u51fa\u529b\r\n    output.setContent(payload);\r\n\r\n    return output;\r\n}\r\n\r\n\/\/API\u547c\u3073\u51fa\u3057\u6642\u306b\u52d5\u4f5c\u3059\u308b\u95a2\u6570\r\nfunction doGet(e){\r\n    const key = e.parameter.key;\r\n    const apiKey = '\u3010\u63a5\u7d9a\u7528\u30ad\u30fc\u3011';\r\n\r\n    if( key != apiKey ){\r\n        return ContentService.createTextOutput('\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002');\r\n    }\r\n\r\n    return getHoliday();\r\n}<\/pre>\n<p>\u30ab\u30ec\u30f3\u30c0\u30fcID\u306f\u5148\u307b\u3069\u30e1\u30e2\u3063\u305f\u3082\u306e\u306b\u66f8\u304d\u63db\u3048\u3001\u63a5\u7d9a\u7528\u30ad\u30fc\u306f\u9069\u5f53\u306a\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3002<\/p>\n<h3>\u30c7\u30d7\u30ed\u30a4<\/h3>\n<p>\u5916\u90e8\u304b\u3089\u63a5\u7d9a\u3067\u304d\u308b\u3088\u3046\u30c7\u30d7\u30ed\u30a4\u306e\u5fc5\u8981\u3042\u308a\u3002<\/p>\n<p>\u300c\u53f3\u4e0a\u306e\u30c7\u30d7\u30ed\u30a4\u30dc\u30bf\u30f3\u2192\u65b0\u3057\u3044\u30c7\u30d7\u30ed\u30a4\u300d\u306b\u9032\u307f\u300c\u8aac\u660e\u300d\u306f\u9069\u5f53\u3001\u300c\u7a2e\u985e\u306e\u9078\u629e\u300d\u306f\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u3001\u300c\u6b21\u306e\u30e6\u30fc\u30b6\u30fc\u3068\u3057\u3066\u306e\u5b9f\u884c\u300d\u3092\u81ea\u5206\u3001\u300c\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30e6\u30fc\u30b6\u30fc\u300d\u3092\u5168\u54e1\u3067\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<p>\u4f55\u6545\u304b\u521d\u56de\u30c7\u30d7\u30ed\u30a4\u6642\u306f\u300c\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30e6\u30fc\u30b6\u30fc\u300d\u306b\u5168\u54e1\u306e\u9078\u629e\u80a2\u304c\u7121\u304b\u3063\u305f\u3002\u300c\u30c7\u30d7\u30ed\u30a4\u3092\u7ba1\u7406\u2192\u30a2\u30fc\u30ab\u30a4\u30d6\u300d\u3067\u524a\u9664\u3059\u308b\u30682\u56de\u76ee\u4ee5\u964d\u304b\u3089\u306f\u5168\u54e1\u3092\u9078\u629e\u3067\u304d\u305f\u3002<\/p>\n<p>\u5c1a\u3001\u30c7\u30d7\u30ed\u30a4\u306b\u6210\u529f\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306aURL\u304c\u767a\u884c\u3055\u308c\u308b\u306e\u3067\u30e1\u30e2\u3063\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">https:\/\/script.google.com\/macros\/s\/xxxxxxxxxxxxxxxxxxxx\/exec<\/pre>\n<p>&nbsp;<\/p>\n<h2>PHP(\u30ea\u30af\u30a8\u30b9\u30c8\u5074)<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\n$api = file_get_contents('https:\/\/script.google.com\/macros\/s\/xxxxxxxxxxxxxxxxxxxxx\/exec?key=\u3010\u63a5\u7d9a\u7528\u30ad\u30fc\u3011');\r\n$holiday = json_decode($api, true);\r\n\r\n\/\/JSON\u30d5\u30a1\u30a4\u30eb\u7528\u306e\u5236\u9650\u6642\u9593\r\n$holiday['limit'] = date('Y-m-d H:i:s', strtotime('+1 day'));\r\n\r\n\/\/JSON\u30d5\u30a1\u30a4\u30eb\u4e0a\u66f8\u304d\u4fdd\u5b58\r\nfile_put_contents('.\/holiday.json', json_encode($holiday));<\/pre>\n<p>\u63a5\u7d9a\u7528\u30ad\u30fc\u306fGAS\u5074\u3068\u63c3\u3048\u308b\u3053\u3068\u3002<\/p>\n<p>\u5b9f\u884c\u3059\u308b\u3068holiday.json\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u308b\u7b48\u3002\u751f\u6210\u3055\u308c\u306a\u3044\u5834\u5408\u306f\u30d5\u30a9\u30eb\u30c0\u306e\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u57fa\u672c\u7684\u306b\u306f<a href=\"https:\/\/taitan916.info\/blog\/archives\/3338\" target=\"_blank\" rel=\"noopener\">\u4ee5\u524d\u4f5c\u6210\u3057\u305f\u795d\u65e5API<\/a>\u306e\u5f62\u3067\u5bfe\u5fdc\u3067\u304d\u305f\u3002\u3053\u3063\u3061\u306e\u65b9\u304c\u5de5\u6570\u304c\u304b\u304b\u3089\u306a\u3044\u3057\u3001\u304a\u5ba2\u69d8\u306b\u3068\u3063\u3066\u306fGoogle\u30ab\u30ec\u30f3\u30c0\u30fc\u306e\u65b9\u304c\u4f7f\u3044\u3084\u3059\u3044\u3068\u3044\u3063\u305f\u5834\u5408\u3082\u3042\u308a\u305d\u3046\u306a\u306e\u3067\u5f15\u304d\u51fa\u3057\u3068\u3057\u3066\u6301\u3063\u3066\u304a\u304d\u305f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u58f2\u5e97\u7b49\u306e\u30b5\u30a4\u30c8\u3067\u55b6\u696d\u65e5\u30ab\u30ec\u30f3\u30c0\u30fc\u307f\u305f\u3044\u306a\u3082\u306e\u3092\u8868\u793a\u3055\u305b\u308b\u969b\u306b\u4eca\u307e\u3067\u306fPHP\u3067\u7ba1 ... <\/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":[72,70],"tags":[],"class_list":["post-4605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google-apps-script","category-google"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4605","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=4605"}],"version-history":[{"count":2,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4605\/revisions"}],"predecessor-version":[{"id":4607,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4605\/revisions\/4607"}],"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=4605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=4605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=4605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}