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
相关产品推荐
相关产品推荐

