> 文章列表 > c语言获取天气信息示例(通过心知天气api获取)

c语言获取天气信息示例(通过心知天气api获取)

c语言获取天气信息示例(通过心知天气api获取)

关于curl/curl.h库的使用,参考下述内容:

VS2010编译libcurl库并简单使用(c语言)_西晋的no1的博客-CSDN博客

1.先在心知天气注册,获取私钥:  https://www.seniverse.com/dashboard

2.将私钥放入下述url中【私钥” 直接请求方式】

将 API 密钥中的“私钥”作为 API 请求中的 key 参数值: https://api.seniverse.com/v3/weather/now.json?key=your_private_key&location=beijing&language=zh-Hans&unit=c

说明:1.此方式较为方便,但请注意不要泄漏你的“私钥”。

           2.上述url中的参数含义和取值参考文章: 接口中的通用参数 · 心知科技

3.C语言代码

#include <curl/curl.h>
#include <Windows.h>int main() {SetConsoleOutputCP(CP_UTF8);CURL* curl = curl_easy_init();if (curl) {CURLcode res;curl_easy_setopt(curl, CURLOPT_URL, "https://api.seniverse.com/v3/weather/now.json?key=your_private_key&location=beijing&language=zh-Hans&unit=c");res = curl_easy_perform(curl);curl_easy_cleanup(curl);}return 0;
}

4.心知天气-V3天气现象代码说明及图片下载

V3天气现象代码说明 · 心知科技