{"id":4293,"date":"2014-03-24T16:19:11","date_gmt":"2014-03-24T07:19:11","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=4293"},"modified":"2014-03-24T16:19:11","modified_gmt":"2014-03-24T07:19:11","slug":"google-apps-script%e3%82%b5%e3%82%a4%e3%83%89%e3%83%90%e3%83%bc%e3%81%8b%e3%82%89%e7%94%bb%e5%83%8f%e3%82%92%e3%83%89%e3%82%ad%e3%83%a5%e3%83%a1%e3%83%b3%e3%83%88%e3%81%ab%e6%8c%bf%e5%85%a5%e3%81%99-2","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=4293","title":{"rendered":"[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u6587\u66f8)"},"content":{"rendered":"<p>\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=4284\" title=\"[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8)\" target=\"_blank\">[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8)<\/a>\u300d\u3067\u306f\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u4e0a\u306b\u753b\u50cf\u3092\u633f\u5165\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u6587\u66f8\u306e\u5834\u5408\u306e\u51e6\u7406\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><strong>\u30fb\u30b3\u30fc\u30c9.gs<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var ui = DocumentApp.getUi();\r\nvar html = HtmlService.createHtmlOutputFromFile('Pixabay').setTitle('Pixabay\u304b\u3089\u753b\u50cf\u3092\u633f\u5165').setWidth(300);\r\n\r\nfunction onOpen(e){\r\n    ui.showSidebar(html);\r\n}\r\n\r\nfunction searchPixabayPhoto(txt){\r\n    var content = '';\r\n    var user = ''; \/\/Pixabay\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u3053\u3053\u306b\u5165\u529b\r\n    var key = ''; \/\/Pixabay\u306eAPI\u30ad\u30fc\u3092\u3053\u3053\u306b\u5165\u529b\r\n    var url = 'http:\/\/pixabay.com\/api\/?username=' + user + '&amp;key=' + key + '&amp;lang=ja&amp;image_type=all&amp;orientation=all&amp;order=popular&amp;search_term=' + encodeURIComponent(txt);\r\n    var res = UrlFetchApp.fetch(url);\r\n    var data = JSON.parse(res.getContentText());\r\n    if(parseFloat(data.totalHits) &lt; 1){\r\n        content = '&lt;h3&gt;\u5199\u771f\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&lt;\/h3&gt;';\r\n    }else{\r\n        content = '&lt;ol&gt;';\r\n        data.hits.forEach(function(item){\r\n            content += '&lt;li&gt;&lt;img src=&quot;' + item.previewURL + '&quot; alt=&quot;' + item.webformatURL + '&quot; title=&quot;\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u753b\u50cf\u3092\u633f\u5165\u3057\u307e\u3059\u3002&quot;&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;' + item.pageURL + '&quot; target=&quot;_blank&quot; title=&quot;\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u5199\u771f\u306e\u30da\u30fc\u30b8\u3092\u958b\u304d\u307e\u3059\u3002&quot;&gt;PageURL&lt;\/a&gt;&lt;\/li&gt;&lt;\/ul&gt;&lt;\/li&gt;';\r\n        });\r\n        content += '&lt;\/ol&gt;';\r\n    }\r\n    html.append(content);\r\n    ui.showSidebar(html); \/\/\u30b5\u30a4\u30c9\u30d0\u30fc\u518d\u63cf\u753b\r\n}\r\n\r\nfunction insertPixabayPhoto(url){\r\n    var dat = UrlFetchApp.fetch(url);\r\n    DocumentApp.getActiveDocument().getBody().insertImage(0, dat.getBlob());\r\n}<\/pre>\n<p><strong>\u30fbPixabay.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;meta charset=&quot;UTF-8&quot;&gt;\r\n        &lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/ssl.gstatic.com\/docs\/script\/css\/add-ons.css&quot;&gt;\r\n        &lt;style&gt;\r\n            #main{padding:20px;}\r\n            img:hover{cursor:pointer;}\r\n        &lt;\/style&gt;\r\n        &lt;script src=&quot;\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.0\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n        &lt;script&gt;\r\n            $(function(){\r\n                $(&quot;#q&quot;).keypress(function(e){\r\n                    switch(e.which){\r\n                        case 13: \/\/Enter\u30ad\u30fc\u5165\u529b\u6642\u306e\u51e6\u7406\r\n                            google.script.run.searchPixabayPhoto($(this).val());\r\n                            break;\r\n                    }\r\n                });\r\n                \r\n                $(&quot;img&quot;).click(function(){\r\n                    google.script.run.insertPixabayPhoto($(this).attr(&quot;alt&quot;));\r\n                });\r\n            });\r\n        &lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;\r\n        &lt;div id=&quot;main&quot;&gt;\r\n            &lt;input id=&quot;q&quot; type=&quot;text&quot; title=&quot;\u30ad\u30fc\u30ef\u30fc\u30c9\u5165\u529b\u5f8cEnter\u30ad\u30fc\u3092\u62bc\u3057\u3066\u304f\u3060\u3055\u3044\u3002&quot;&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><a href=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GoogleAppsScript_08_01.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GoogleAppsScript_08_01.jpg\" alt=\"GoogleAppsScript_08_01\" width=\"1062\" height=\"687\" class=\"alignnone size-full wp-image-4294\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GoogleAppsScript_08_01.jpg 1062w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GoogleAppsScript_08_01-300x194.jpg 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/GoogleAppsScript_08_01-1024x662.jpg 1024w\" sizes=\"auto, (max-width: 1062px) 100vw, 1062px\" \/><\/a><\/p>\n<p>\u300c<a href=\"\/\/www.ka-net.org\/blog\/?p=4284\" title=\"[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8)\" target=\"_blank\">[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8)<\/a>\u300d\u306e\u30b3\u30fc\u30c9\u3068\u306e\u9055\u3044\u306f\u753b\u50cf\u633f\u5165\u90e8\u5206\u3060\u3051\u3067\u305d\u306e\u4ed6\u306f\u307b\u3068\u3093\u3069\u540c\u3058\u3067\u3059\u3002<\/p>\n<ul>\n<li>getBlob()<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/developers.google.com\/apps-script\/reference\/url-fetch\/http-response?hl=ja#getBlob%28%29\" target=\"_blank\" title=\"getBlob()\">https:\/\/developers.google.com\/apps-script\/reference\/url-fetch\/http-response?hl=ja#getBlob%28%29<\/a><\/li>\n<li>insertImage(childIndex, image)<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/developers.google.com\/apps-script\/reference\/document\/body?hl=ja#insertImage%28Integer,BlobSource%29\" target=\"_blank\" title=\"insertImage(childIndex, image)\">https:\/\/developers.google.com\/apps-script\/reference\/document\/body?hl=ja#insertImage%28Integer,BlobSource%29<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u300c[Google Apps Script]\u30b5\u30a4\u30c9\u30d0\u30fc\u304b\u3089\u753b\u50cf\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u633f\u5165\u3059\u308b(\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8)\u300d\u3067\u306f\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u4e0a\u306b\u753b\u50cf\u3092\u633f\u5165\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u6587\u66f8\u306e\u5834\u5408\u306e\u51e6\u7406\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002 \u30fb\u30b3\u30fc [&hellip;]","protected":false},"author":1,"featured_media":7113,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[126],"tags":[],"class_list":["post-4293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Google.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-17f","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4293"}],"version-history":[{"count":3,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4293\/revisions"}],"predecessor-version":[{"id":4297,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4293\/revisions\/4297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7113"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}