iT邦幫忙

2025 iThome 鐵人賽

DAY 25
0
Software Development

從入門到應用:30 天學會 Postman API 測試系列 第 25

Day 25:串接天氣 API(帶入動態參數)

  • 分享至 

  • xImage
  •  

1️⃣ API Key 的概念
許多 API 需要 API Key 來驗證使用者身份(就像「門票」)。
沒有正確的 Key → 就會得到 401 Unauthorized 錯誤。
👉 學到:API Key 的用途、怎麼申請與放到參數裡。
2️⃣ URL 與查詢參數(Query Parameters)
API URL 可以分成 基本路徑 + 參數。
基本路徑:https://api.openweathermap.org/data/2.5/weather
參數:?q=Taipei&appid=xxx&units=metric
👉 學到:如何在 Postman Params 分頁設定參數,而不是寫死在 URL 裡。

今天要用的方法是GET,使用的URL是上面的基本路徑,在開始之前要到 https://home.openweathermap.org/api_keys 這個網址裡新建一個API keys,不能用他預設的,我是用之後都出現401的錯誤,所以要新建並且等個幾分鐘那個API keys才能正式生效https://ithelp.ithome.com.tw/upload/images/20251002/20178797ca970JTIMq.jpg
接下來到Params(就是動態參數)貼上
| Key | Value |
| q | Taipei |
| appid | 你的 API Key |
| units | metric (攝氏) |
這樣我們隨時都可以只改裡面單一的東西,不用從網址裡一直改
https://ithelp.ithome.com.tw/upload/images/20251002/20178797t1NiJVjkvG.jpg
可以看到現在溫度、體感溫度、最高溫或最低溫等等


上一篇
Day 24:串接金流 API(模擬付款流程)
下一篇
Day 26:整合多個 API 做一個小專案(例:查天氣 + 存到 DB)
系列文
從入門到應用:30 天學會 Postman API 測試26
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言