{"id":2343,"date":"2021-02-16T01:48:10","date_gmt":"2021-02-15T17:48:10","guid":{"rendered":"https:\/\/wesleymusasi.com\/?p=2343"},"modified":"2021-05-26T21:40:10","modified_gmt":"2021-05-26T13:40:10","slug":"openweathermap%e5%a4%a9%e6%b0%a3api%e5%af%a6%e4%be%8b%e5%8f%83%e8%80%83-by-chiaroluna","status":"publish","type":"post","link":"https:\/\/wesleymusasi.com\/?p=2343","title":{"rendered":"OpenWeatherMap\u5929\u6c23API\u5be6\u4f8b\u53c3\u8003 By Chiaroluna"},"content":{"rendered":"\n<p>\u3000\u3000\u8a71\u8aaa\u5927\u9b6f\u86c7\u9019\u5e7e\u5929\u90fd\u5728\u627e\u300cAPI\u300d\u7684\u61c9\u7528\u5be6\u4f8b\uff0c\u505a\u70ba\u8a2d\u8a08\u300c\u865f\u78bc\u51f6\u5409\u6e2c\u7b97\u300dAPP\u7684\u53c3\u8003\uff0c\u7e3d\u7b97\u7687\u5929\u4e0d\u8ca0\u82e6\u5fc3\u4eba\uff0c\u7d42\u65bc\u5728\u4f5c\u8005Chiaroluna\u7684\u300c<strong><span style=\"text-decoration: underline;\"><span class=\"has-inline-color has-vivid-red-color\"><a href=\"https:\/\/ithelp.ithome.com.tw\/m\/articles\/10192206\" target=\"_blank\" rel=\"noopener\">[30apis] Day 1 : OpenWeatherMap<\/a><\/span><\/span><\/strong>\u300d\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u627e\u5230\u4e86\u7b54\u6848\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u4f5c\u8005Chiaroluna\u505a\u9019\u500b\u5929\u6c23App\u7684\u76ee\u7684\uff0c\u4e3b\u8981\u662f\u7df4\u7fd2Web API\u7684\u4f7f\u7528\uff0c\u53ea\u8981\u80fd\u5920\u63a5\u901aOpenWeatherMap\u7684API\u5c31\u597d\u3002\u6240\u4ee5\u9019\u500b\u6700\u57fa\u672c\u7684\u5929\u6c23APP\u53ea\u6703\u6709\u4e00\u500b\u529f\u80fd\uff1a\u300c\u986f\u793a\u53f0\u5317\u7576\u4e0b\u7684\u5929\u6c23\u72c0\u6cc1\u300d(<strong><span style=\"text-decoration: underline;\"><span class=\"has-inline-color has-vivid-red-color\"><a href=\"https:\/\/codepen.io\/chrysophyta\/pen\/ypOmaJ\" target=\"_blank\" rel=\"noopener\">Demo\u793a\u7bc4\u8acb\u9ede\u6211<\/a><\/span><\/span><\/strong>)\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u800c\u5927\u9b6f\u86c7\u505a\u865f\u78bc\u51f6\u5409\u6e2c\u7b97App\u7684\u76ee\u7684\uff0c\u4e5f\u53ea\u662f\u8981\u80fd\u5920\u63a5\u901a\u597d\u53cbJason\u958b\u767c\u7684\u547d\u7406\u8cc7\u6599\u5eabAPI\u5c31\u597d\u3002\u865f\u78bc\u51f6\u5409\u6e2c\u7b97App\u4e5f\u53ea\u6703\u6709\u4e00\u500b\u529f\u80fd\uff1a\u300c\u986f\u793a\u7576\u4e8b\u4eba\u8f38\u5165\u865f\u78bc\u7684\u5409\u51f6\u72c0\u6cc1\u300d\uff0c\u4e0d\u8ad6\u8f38\u5165\u7684\u662f\u96fb\u8a71\u865f\u78bc\u9084\u662f\u8eca\u724c\u865f\u78bc\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u5927\u9b6f\u86c7\u627e\u5230\u9019\u500b\u5be6\u4f8b\u4e4b\u5f8c\uff0c\u8d95\u7dca\u548c\u597d\u53cb\u806f\u7d61\uff0c\u78ba\u8a8d\u9019\u500b\u7bc4\u4f8b\u7684\u5be6\u7528\u53c3\u8003\u50f9\u503c\u3002\u597d\u53cb\u8aaa\u5dee\u4e0d\u591a\u5c31\u662f\u9019\u6a23\uff0c\u5c31\u7b49\u4ed6\u8acb\u5de5\u7a0b\u5e2b\u6e96\u5099\u597dAPI\u7684\u898f\u683c\u8aaa\u660e\u6587\u4ef6\uff0c\u4ee5\u53ca\u751f\u6210\u3001\u9a57\u8b49API Key\u7684\u6a5f\u5236\uff0c\u5f8c\u9762\u5c31\u53ef\u4ee5\u6b63\u5f0f\u64b0\u5beb\u7a0b\u5f0f\u4f86\u505a\u5be6\u505a\u4e86\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u4e0d\u904e\uff0c\u9019\u500b\u7bc4\u4f8b\u9084\u7f3a\u5c11\u4e00\u500b\u529f\u80fd\uff0c\u90a3\u5c31\u662f\u4f7f\u7528\u8005\u300c\u8f38\u5165\u865f\u78bc\u300d\u7684\u90e8\u5206\uff0c\u6240\u4ee5\u9019\u9700\u8981\u6211\u81ea\u5df1\u53bb\u627e\u5be6\u4f8b\u4f86\u88dc\u9f4a\u3002\u57fa\u672c\u4e0a\uff0c\u4ed6\u8a8d\u70ba\u61c9\u8a72\u4e0d\u6703\u5f88\u56f0\u96e3\uff0c\u8981\u6211\u518d\u52a0\u4e00\u628a\u52c1\uff0c\u5982\u679cWeb API \u80fd\u505a\u7684\u5230\uff0c\u90a3 APP \u5c31\u4e0d\u9060\u4e86\uff01<\/p>\n\n\n\n<p>\u3000\u3000\u6b64\u6642\u5927\u9b6f\u86c7\u81c9\u4e0a\u4e09\u689d\u7dda\uff0c\u4e8b\u60c5\u6709\u9019\u9ebc\u7c21\u55ae\u5c31\u597d\u4e86\uff01<\/p>\n\n\n\n<p>\u3000\u3000\u4e0d\u7ba1\u600e\u9ebc\u8aaa\uff0c\u65e2\u7136\u6709\u73fe\u6210\u7684\u7bc4\u4f8b\u53ef\u4ee5\u53c3\u8003\uff0c\u7e3d\u6bd4\u778e\u5b50\u6478\u8c61\u8981\u4f86\u7684\u597d\u3002\u57fa\u672c\u4e0a\uff0c\u5927\u9b6f\u86c7\u5c31\u7b49\u597d\u53cb\u628aAPI\u76f8\u95dc\u524d\u7f6e\u4f5c\u696d\u6e96\u5099\u59a5\u7576\uff0c\u63a5\u4e0b\u4f86\u5c31\u6703\u5148\u505a\u4e00\u500bWeb API\u7684\u61c9\u7528\uff0c\u7136\u5f8c\u5d4c\u5165\u5230\u5927\u9b6f\u86c7\u7684\u7db2\u7ad9\u88e1\u982d\uff0c\u63d0\u4f9b\u7d66\u7db2\u53cb\u514d\u8cbb\u8a66\u7528\u300c\u865f\u78bc\u5409\u51f6\u6e2c\u7b97\u300d\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u7b49\u5230\u4e00\u5207\u90fd\u6c92\u6709\u554f\u984c\u4e4b\u5f8c\uff0c\u5927\u9b6f\u86c7\u518d\u5c07Web API\u8a2d\u8a08\u6210APP\uff0c\u4e26\u52a0\u5165AdMob\u5ee3\u544a\u529f\u80fd\uff0c\u6700\u5f8c\u518d\u4e0a\u67b6\u5230Google Play Store\uff0c\u9032\u884c\u5ee3\u544a\u71df\u5229\u5275\u6536\u7684\u53ef\u80fd\u6027\u63a2\u7d22\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u6240\u8b02\u300c\u95dc\u95dc\u96e3\u904e\u95dc\u95dc\u904e\u300d\uff0c\u5927\u9b6f\u86c7\u662f\u7a0b\u5f0f\u8a2d\u8a08\u7d20\u4eba\uff0c\u5728\u6c92\u6709\u4eba\u53ef\u4ee5\u8acb\u6559\u4e4b\u4e0b\uff0c\u6211\u4e5f\u53ea\u80fd\u81ea\u5df1\u786c\u8457\u982d\u76ae\u5f80\u524d\u8d70\u3002\u76ee\u524d\u9084\u7b97\u9806\u5229\uff0c\u5927\u9b6f\u86c7\u5e0c\u671b\u65e9\u65e5\u80fd\u5c07\u6210\u679c\u7aef\u51fa\u4f86\uff0c\u8b93\u7db2\u53cb\u5011\u53ef\u4ee5\u514d\u8cbb\u8a66\u7528\u9019\u500b\u300c\u865f\u78bc\u6e2c\u5409\u51f6\u300d\u529f\u80fd\uff0c\u770b\u770b\u7a76\u7adf\u6709\u6c92\u6709\u5e02\u5834\u9700\u6c42\u5b58\u5728\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u4ee5\u4e0b\uff0c\u5c31\u662f\u5927\u9b6f\u86c7\u7684\u5be6\u4f8b\u6a21\u4eff\u8a66\u4f5c\u3002<\/p>\n\n\n\n<p style=\"font-size:24px\"><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">\u4e00\u3001\u8a3b\u518aOpenWeather\uff0c\u7533\u8acbAPI key\u3002<\/span><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"390\" src=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=1024%2C390&#038;ssl=1\" alt=\"\" class=\"wp-image-2347\" srcset=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=1024%2C390&amp;ssl=1 1024w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=300%2C114&amp;ssl=1 300w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=768%2C293&amp;ssl=1 768w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=750%2C286&amp;ssl=1 750w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?resize=1140%2C434&amp;ssl=1 1140w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-81.png?w=1197&amp;ssl=1 1197w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p style=\"font-size:24px\"><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">\u4e8c\u3001\u4fee\u6539\u4f5c\u8005\u7a0b\u5f0f\u78bc\uff0c\u6539\u57ce\u5e02\u70baTainan\u4e26\u66ff\u63db\u6210\u5927\u9b6f\u86c7\u7684API Key\uff0c\u5176\u9918\u4e0d\u8b8a\u3002<\/span><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"421\" height=\"420\" src=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-82.png?resize=421%2C420&#038;ssl=1\" alt=\"\" class=\"wp-image-2348\" srcset=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-82.png?w=421&amp;ssl=1 421w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-82.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-82.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-82.png?resize=75%2C75&amp;ssl=1 75w\" sizes=\"(max-width: 421px) 100vw, 421px\" \/><\/figure>\n\n\n\n<p style=\"font-size:24px\"><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">\u4e09\u3001\u7a0b\u5f0f\u57f7\u884c\u5982\u4e0b\u3002<\/span><\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u7a0b\u5f0f\u5728CodePen\u57f7\u884c\u826f\u597d\uff0c\u4f46\u5927\u9b6f\u86c7\u8a66\u8457\u62f7\u8c9d\u7a0b\u5f0f\u78bc\u5230\u6587\u7ae0\u88e1\uff0c\u4e0d\u8ad6\u5340\u584a\u662f\u7528\u81ea\u5b9a\u7fa9HTML\u3001\u9084\u662f\u7a0b\u5f0f\u78bc\u5d4c\u5165(\u4e0b\u9762\u7bc4\u4f8b\u5373\u662f)\uff0c\u4f46\u90fd\u6c92\u6709\u8fa6\u6cd5\u6b63\u78ba\u7684\u986f\u793a\u7d50\u679c\u3002\u5982\u679c\u6709\u7a0b\u5f0f\u9ad8\u624b\uff0c\u4e5f\u8acb\u60a8\u6307\u9ede\u4e00\u4e0b\u5927\u9b6f\u86c7\u554f\u984c\u662f\u51fa\u5728\u54ea\u88e1\uff1f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"430\" height=\"509\" src=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-83.png?resize=430%2C509&#038;ssl=1\" alt=\"\" class=\"wp-image-2357\" srcset=\"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-83.png?w=430&amp;ssl=1 430w, https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/image-83.png?resize=253%2C300&amp;ssl=1 253w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong><span class=\"has-inline-color has-vivid-purple-color\">\u3000@\u53ea\u8cbcJS\u7a0b\u5f0f\u78bc<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function makeRequest() {\n  xhr = new XMLHttpRequest();\n\n  xhr.onload = function() {\n    var response = JSON.parse(this.responseText);\n    var city = response.city.name + \", \" + response.city.country;\n    var weatherTitle = response.list&#91;0].weather&#91;0].main;\n    var temp = response.list&#91;0].main.temp + \"\u00b0\";\n\n    var weatherContainer = document.querySelector(\"#weather\");\n    weatherContainer.innerHTML = city + \"&lt;br\/&gt;\" + weatherTitle + \"&lt;br\/&gt;\" + temp;\n  };\n  xhr.open(\n    \"GET\",\n    \"https:\/\/api.openweathermap.org\/data\/2.5\/forecast?q=Tainan,tw&amp;APPID=d79b2310e9aa9004a8ac3066ddac6d5a&amp;lang=zh_tw&amp;units=metric\",\n    true\n  );\n  xhr.send();\n}\nmakeRequest();<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">\u3000<strong><span class=\"has-inline-color has-vivid-purple-color\">@\u81ea\u5b9a\u7fa9HTML<\/span><\/strong><\/p>\n\n\n\n<div id=\"weather\">\nfunction makeRequest() {\n  xhr = new XMLHttpRequest();\n\n  xhr.onload = function() {\n    var response = JSON.parse(this.responseText);\n    var city = response.city.name + &#8220;, &#8221; + response.city.country;\n    var weatherTitle = response.list[0].weather[0].main;\n    var temp = response.list[0].main.temp + &#8220;\u00b0&#8221;;\n\n    var weatherContainer = document.querySelector(&#8220;#weather&#8221;);\n    weatherContainer.innerHTML = city + &#8220;<br\/>&#8221; + weatherTitle + &#8220;<br\/>&#8221; + temp;\n  };\n  xhr.open(\n    &#8220;GET&#8221;,\n    &#8220;https:\/\/api.openweathermap.org\/data\/2.5\/forecast?q=Tainan,tw&#038;APPID=d79b2310e9aa9004a8ac3066ddac6d5a&#038;lang=zh_tw&#038;units=metric&#8221;,\n    true\n  );\n  xhr.send();\n}\nmakeRequest();  \n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u8a71\u8aaa\u5927\u9b6f\u86c7\u9019\u5e7e\u5929\u90fd\u5728\u627e\u300cAPI\u300d\u7684\u61c9\u7528\u5be6\u4f8b\uff0c\u505a\u70ba\u8a2d\u8a08\u300c\u865f\u78bc\u51f6\u5409\u6e2c\u7b97\u300dAPP\u7684\u53c3\u8003\uff0c\u7e3d\u7b97\u7687\u5929\u4e0d\u8ca0\u82e6\u5fc3\u4eba\uff0c\u7d42\u65bc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2344,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"lc_iscn_info":[],"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,329,38],"tags":[],"class_list":["post-2343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-09000000-selfstudy_buleprint","category-api-application","category-09030000-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/wesleymusasi.com\/wp-content\/uploads\/2021\/02\/Open.jpg?fit=1256%2C518&ssl=1","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcKMYa-BN","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/posts\/2343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2343"}],"version-history":[{"count":5,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/posts\/2343\/revisions"}],"predecessor-version":[{"id":2362,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/posts\/2343\/revisions\/2362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=\/wp\/v2\/media\/2344"}],"wp:attachment":[{"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wesleymusasi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}