How to retrieve the list of all GitHub repositories of a person?

后端 未结 15 1226
一个人的身影
一个人的身影 2020-12-02 05:43

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 na

15条回答
  •  独厮守ぢ
    2020-12-02 06:12

    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.

提交回复
热议问题