You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python调用GitHub API获取仓库星标时序数据无法获取时间戳问题

GitHub API获取星标时间戳配置修正方案

你使用的默认application/vnd.github.v3+json媒体类型仅会返回打星用户的基础信息,要获取附带星标创建时间的响应,需要修改Accept请求头的取值:

  • 将请求头中Accept参数替换为application/vnd.github.star+json,这是GitHub为stargazers接口提供的专用响应格式,会额外返回starred_at字段记录打星时间戳。

修正后的代码如下:

import requests
url = "https://api.github.com/repos/flutter/flutter/stargazers?per_page=1"
repo_response = requests.get(url,headers={'Accept': 'application/vnd.github.star+json'})
print(repo_response.json())

修正后返回的响应结构会包含两个顶层字段:

  • starred_at:用户给仓库打星标的UTC时间戳
  • user:原默认格式返回的打星用户信息

内容的提问来源于stack exchange,提问作者Nyx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 11:51:02