如何查询 Github 注册时间
链接查询
这种办法是最简单粗暴的,直接使用浏览器访问下面的链接,把地址中的 user_name
替换成自己的用户名即可。返回值中的 created_at
即为Github创建时间
https://api.github.com/users/user_name
例如我的用户名为 XintaoPeach
,那么我的访问地址为
https://api.github.com/users/XintaoPeach
返回值如下:
{
'login': 'XintaoPeach',
'id': 104210585,
'node_id': 'U_kgDOBjYgmQ',
'avatar_url': 'https://avatars.githubusercontent.com/u/104210585?v=4',
'gravatar_id': '',
'url': 'https://api.github.com/users/XintaoPeach',
'html_url': 'https://github.com/XintaoPeach',
'followers_url': 'https://api.github.com/users/XintaoPeach/followers',
'following_url': 'https://api.github.com/users/XintaoPeach/following{/other_user}',
'gists_url': 'https://api.github.com/users/XintaoPeach/gists{/gist_id}',
'starred_url': 'https://api.github.com/users/XintaoPeach/starred{/owner}{/repo}',
'subscriptions_url': 'https://api.github.com/users/XintaoPeach/subscriptions',
'organizations_url': 'https://api.github.com/users/XintaoPeach/orgs',
'repos_url': 'https://api.github.com/users/XintaoPeach/repos',
'events_url': 'https://api.github.com/users/XintaoPeach/events{/privacy}',
'received_events_url': 'https://api.github.com/users/XintaoPeach/received_events',
'type': 'User',
'site_admin': False,
'name': 'Xintao',
'company': 'Wuhan Textile University',
'blog': 'https://github.com/XintaoPeach',
'location': 'Wuhan,China',
'email': None,
'hireable': None,
'bio': None,
'twitter_username': None,
'public_repos': 10,
'public_gists': 0,
'followers': 1,
'following': 1,
'created_at': '2022-04-22T13:38:28Z',
'updated_at': '2023-11-23T11:55:40Z'
}
所以我的创建时间就是 2022-04-22T13:38:28Z
Python
这种方式是我突发奇想,既然浏览器都是 GET
类型,我为什么不能写一个简单的 Python 来访问和筛选呢?
想到就去做!于是我写了下面的简单Python程序,成功运行!
如果你想试一下就可以直接拿去使用。
import requests
username = input('请输入用户名:')
base_url = "https://api.github.com/users"
url = f'{base_url}/{username}'
response = requests.get(url)
if response.status_code == 200:
username = response.json()['login']
creat_time = response.json()['created_at']
print('用户名:', username)
print('创建时间:', creat_time)
else:
print(response.status_code)
print(response.text)
运行后的结果如下:
用户名: XintaoPeach
创建时间: 2022-04-22T13:38:28Z
这样看就一目了然了
注意事项
这个调用API是有速率限制的,具体可以参考【官方文档】
今天的分享就到此为止,感谢小伙伴的阅读。