C# example of downloading GitHub private repo programmatically

前端 未结 4 1131
广开言路
广开言路 2020-12-16 17:10

I see that the download path for a GitHub repo is of the form

https://github.com/{username}/{reponame}/archive/{branchname}.zip

For a priva

4条回答
  •  渐次进展
    2020-12-16 18:00

    See this guide on creating a personal access token then run the following:

    var githubToken = "token";
    var request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/$OWNER/$REPO/contents/$PATH");
    request.Headers.Add(HttpRequestHeader.Authorization, string.Concat("token ", githubToken));
    request.Accept = "application/vnd.github.v3.raw";
    request.UserAgent = "test app"; //user agent is required https://developer.github.com/v3/#user-agent-required
    using (var response = request.GetResponse())
    {
        var encoding = System.Text.ASCIIEncoding.UTF8;
        using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
        {
            var fileContent = reader.ReadToEnd();
        }
    }
    

提交回复
热议问题