#223 串接 GitHub API 顯示可愛的程式 logo
Published in
Apr 24, 2024
最近看到 SAWARATSUKI 大大在 GitHub 分享他繪製的可愛程式 logo,有興趣的朋友也可以串接 GitHub API 做個顯示可愛程式 logo 的 App。
功能需求
- 第一頁顯示名字列表。
使用以下 API 抓取名字列表。
https://api.github.com/repos/SAWARATSUKI/ServiceLogos/contents
欄位 name 是名字,url 是下一頁抓取圖片資訊的網址。
- 第二頁顯示圖片。
從第一頁 JSON 裡的 url 抓取圖片資訊,比方用以下網址抓取 Swift 的資訊。
https://api.github.com/repos/SAWARATSUKI/ServiceLogos/contents/Swift
從 JSON 的 download_url 取得圖片網址。
[
{
"name": "Swift.png",
"path": "Swift/Swift.png",
"sha": "807b288fc745c750d7843c1bad4f0f351c267553",
"size": 87573,
"url": "https://api.github.com/repos/SAWARATSUKI/ServiceLogos/contents/Swift/Swift.png?ref=main",
"html_url": "https://github.com/SAWARATSUKI/ServiceLogos/blob/main/Swift/Swift.png",
"git_url": "https://api.github.com/repos/SAWARATSUKI/ServiceLogos/git/blobs/807b288fc745c750d7843c1bad4f0f351c267553",
"download_url": "https://raw.githubusercontent.com/SAWARATSUKI/ServiceLogos/main/Swift/Swift.png",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/SAWARATSUKI/ServiceLogos/contents/Swift/Swift.png?ref=main",
"git": "https://api.github.com/repos/SAWARATSUKI/ServiceLogos/git/blobs/807b288fc745c750d7843c1bad4f0f351c267553",
"html": "https://github.com/SAWARATSUKI/ServiceLogos/blob/main/Swift/Swift.png"
}
}
]