天文图像图片
其他 官方文档
随机天文图像
基本说明:
接口地址:https://api.nasa.gov/planetary/apod
返回格式:json
请求方式:get
请求示例:https://api.nasa.gov/planetary/apod?api_key=key
请求参数说明:
名称 类型 必填 说明
api_key string 必填 网站密钥 扫码关注公众号
date string 选填 指定日期图片,格式:Y-m-d
start_date string 选填 开始日期,格式:Y-m-d
end_date string 选填 开始日期
count int 选填 如果指定了此项,count则将返回随机选择的图像
thumbs bool 选填 返回视频缩略图的 URL
返回参数说明:
名称 类型 说明
copyright string 版权
date string 日期
explanation string 解释
url string 图片地址
media_type string 资源类型
title string 标题
JSON返回示例:
{
	"copyright": "\nDavid Moulton\n",
	"date": "2024-03-05",
	"explanation": "Is this a painting or a photograph? In this celestial abstract art composed with a cosmic brush, dusty nebula NGC 2170, also known as the Angel Nebula, shines just above the image center. Reflecting the light of nearby hot stars, NGC 2170 is joined by other bluish reflection nebulae, a red emission region, many dark absorption nebulae, and a backdrop of colorful stars. Like the common household items that abstract painters often choose for their subjects, the clouds of gas, dust, and hot stars featured here are also commonly found in a setting like this one --  a massive, star-forming molecular cloud in the constellation of the Unicorn (Monoceros). The giant molecular cloud, Mon R2, is impressively close, estimated to be only 2,400 light-years or so away. At that distance, this canvas would be over 60 light-years across.",
	"hdurl": "https://apod.nasa.gov/apod/image/2403/AngelNebula_Moulton_2516.jpg",
	"media_type": "image",
	"service_version": "v1",
	"title": "NGC 2170: Angel Nebula Abstract Art",
	"url": "https://apod.nasa.gov/apod/image/2403/AngelNebula_Moulton_960.jpg"
}
服务级错误码参照
错误码 说明
- -
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2024/3/5 11:11
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://api.nasa.gov/planetary/apod?api_key=key';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://api.nasa.gov/planetary/apod?api_key=key"
)

func main() {
	queryUrl := fmt.Sprintf("%s",APIURL)
	resp, err := http.Get(queryUrl)
	if err != nil {
		log.Println(err)
		return
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}