鉴权与使用
所有开发者 API(除健康检查外)均需通过 API Key 鉴权。API Key 在请求中通过 Authorization Header 传递。
获取 API Key
- 登录观天者数据站
- 进入「开发者控制台」
- 创建应用,系统会生成一个 API Key
- 复制并妥善保管 API Key(仅在创建时完整显示一次)
API Key 格式
sk-{32位十六进制字符串}
示例:sk-d5d0542bef7e42e2b8909cb7f42af5fb
请求方式
在 HTTP 请求中携带 Authorization Header,值为 Bearer <API Key>:
Authorization: Bearer sk-d5d0542bef7e42e2b8909cb7f42af5fb
代码示例
健康检查无需鉴权,可直接调用:
curl -s https://standard.data-api.skyviewor.host/v1/health
以下示例展示如何携带 API Key 调用天气实况接口(https://standard.data-api.skyviewor.host/v1/weather/observation/point/realtime):
# 更换为您的以 sk- 开头的 API Key 字符串
curl -s \
-H "Authorization: Bearer sk-d5d0542bef7e42e2b8909cb7f42af5fb" \
"https://standard.data-api.skyviewor.host/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852"
import json
import urllib.request
API_BASE = "https://standard.data-api.skyviewor.host"
API_KEY = "sk-d5d0542bef7e42e2b8909cb7f42af5fb" # 更换为您的以 sk- 开头的 API Key 字符串
def call_api(path: str) -> dict:
req = urllib.request.Request(
f"{API_BASE}{path}",
headers={"Authorization": f"Bearer {API_KEY}"},
)
with urllib.request.urlopen(req, timeout=30) as resp:
return json.loads(resp.read().decode())
result = call_api("/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852")
print(result["data"]["records"]["temperature"]) # 气温
const API_BASE = "https://standard.data-api.skyviewor.host";
const API_KEY = "sk-d5d0542bef7e42e2b8909cb7f42af5fb"; // 更换为您的以 sk- 开头的 API Key 字符串
async function callApi(path) {
const resp = await fetch(`${API_BASE}${path}`, {
headers: { Authorization: `Bearer ${API_KEY}` },
});
return resp.json();
}
const result = await callApi("/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852");
console.log(result.data.records.temperature); // 气温
interface ApiResponse {
code: number;
data: { records: { temperature: number } };
}
const API_BASE: string = "https://standard.data-api.skyviewor.host";
const API_KEY: string = "sk-d5d0542bef7e42e2b8909cb7f42af5fb"; // 更换为您的以 sk- 开头的 API Key 字符串
async function callApi(path: string): Promise<ApiResponse> {
const resp = await fetch(`${API_BASE}${path}`, {
headers: { Authorization: `Bearer ${API_KEY}` },
});
return resp.json();
}
const result = await callApi("/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852");
console.log(result.data.records.temperature); // 气温
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
const apiBase = "https://standard.data-api.skyviewor.host"
const apiKey = "sk-d5d0542bef7e42e2b8909cb7f42af5fb" // 更换为您的以 sk- 开头的 API Key 字符串
func main() {
req, _ := http.NewRequest("GET",
apiBase+"/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852", nil)
req.Header.Set("Authorization", "Bearer "+apiKey)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var result map[string]interface{}
json.Unmarshal(body, &result)
records := result["data"].(map[string]interface{})["records"].(map[string]interface{})
fmt.Printf("气温: %v°C\n", records["temperature"])
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ApiExample {
private static final String API_BASE = "https://standard.data-api.skyviewor.host";
private static final String API_KEY = "sk-d5d0542bef7e42e2b8909cb7f42af5fb"; // 更换为您的以 sk- 开头的 API Key 字符串
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(API_BASE + "/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852"))
.header("Authorization", "Bearer " + API_KEY)
.GET().build();
HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
}
}
using System.Net.Http;
using System.Text.Json;
var apiBase = "https://standard.data-api.skyviewor.host";
var apiKey = "sk-d5d0542bef7e42e2b8909cb7f42af5fb"; // 更换为您的以 sk- 开头的 API Key 字符串
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var json = await client.GetStringAsync($"{apiBase}/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852");
using var doc = JsonDocument.Parse(json);
var obs = doc.RootElement.GetProperty("data").GetProperty("records");
Console.WriteLine($"气温: {obs.GetProperty("temperature").GetDouble()}°C");
Console.WriteLine($"湿度: {obs.GetProperty("humidity").GetInt32()}%");
Console.WriteLine($"风速: {obs.GetProperty("wind_speed").GetDouble()} m/s");
$API_BASE = "https://standard.data-api.skyviewor.host";
$API_KEY = "sk-d5d0542bef7e42e2b8909cb7f42af5fb"; // 更换为您的以 sk- 开头的 API Key 字符串
$ch = curl_init("{$API_BASE}/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer {$API_KEY}"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
$obs = $result['data']['records'];
echo "气温: {$obs['temperature']}°C\n";
echo "湿度: {$obs['humidity']}%\n";
echo "风速: {$obs['wind_speed']} m/s\n";
library(httr)
library(jsonlite)
API_BASE <- "https://standard.data-api.skyviewor.host"
API_KEY <- "sk-d5d0542bef7e42e2b8909cb7f42af5fb" # 更换为您的以 sk- 开头的 API Key 字符串
resp <- GET(
paste0(API_BASE, "/v1/weather/observation/point/realtime"),
query = list(lat = 39.9312, lon = 116.3852),
add_headers(Authorization = paste("Bearer", API_KEY))
)
result <- fromJSON(content(resp, "text", encoding = "UTF-8"))
cat(sprintf("气温: %.1f°C\n", result$data$records$temperature))
api_base = 'https://standard.data-api.skyviewor.host';
api_key = 'sk-d5d0542bef7e42e2b8909cb7f42af5fb'; % 更换为您的以 sk- 开头的 API Key 字符串
options = weboptions('HeaderFields', {'Authorization', ['Bearer ' api_key]}, 'Timeout', 30);
result = webread([api_base '/v1/weather/observation/point/realtime?lat=39.9312&lon=116.3852'], options);
fprintf('气温: %.1f°C\n', result.data.records.temperature);
fprintf('湿度: %d%%\n', result.data.records.humidity);
fprintf('风速: %.1f m/s\n', result.data.records.wind_speed);