如何检索一个人的所有github仓库列表? [英] How to retrieve the list of all github repositories of a person?

查看:780
本文介绍了如何检索一个人的所有github仓库列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个项目,我们需要在GitHub账户上显示一个人的所有项目。



任何人都可以建议,我怎样才能使用他的git用户名显示某个人的所有git仓库的名字?

解决方案

使用 Github API



/ users /:user / repos



所有用户的公共存储库。如果您需要查找私有存储库,则需要以特定用户身份进行身份验证。您可以使用REST调用:

/ user / repos



找到所有所有用户的回购站。



要在Python中执行此操作,请执行以下操作:

  USER ='AUSER'
API_TOKEN ='ATOKEN'
GIT_API_URL ='https://api.github.com'

def get_api(url):
try:
request = urllib2.Request(GIT_API_URL + url)
ase64string = base64.encodestring('%s / token:%s '%(USER,API_TOKEN))。replace('\ n','')
request.add_header(Authorization,Basic%s%base64string)
result = urllib2.urlopen(请求)
result.close()
除外:
print'无法从%s获取api请求'%url

传递给函数的url是上面示例中的REST url。如果您不需要进行身份验证,那么只需修改该方法以删除添加授权标头。然后,您可以使用简单的GET请求获取任何公共API。


We are working on a project where we need to display all the projects of a person in his repository on GitHub account.

Can anyone suggest, how can I display the names of all the git repositories of a particular person using his git-user name?

解决方案

Use the Github API:

/users/:user/repos

This will give you all the user's public repositories. If you need to find out private repositories you will need to authenticate as the particular user. You can then use the REST call:

/user/repos

to find all the user's repos.

To do this in Python do something like:

USER='AUSER'
API_TOKEN='ATOKEN'
GIT_API_URL='https://api.github.com'

def get_api(url):
    try:
        request = urllib2.Request(GIT_API_URL + url)
        base64string = base64.encodestring('%s/token:%s' % (USER, API_TOKEN)).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string)
        result = urllib2.urlopen(request)
        result.close()
    except:
        print 'Failed to get api request from %s' % url

Where the url passed in to the function is the REST url as in the examples above. If you don't need to authenticate then simply modify the method to remove adding the Authorization header. You can then get any public api url using a simple GET request.

这篇关于如何检索一个人的所有github仓库列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆