Below is an example on how I've been accessing individual files from my public GitHub repository from a console application. Can I do the same for a private repository? I'm not sure how to change the code or if I need to access it with different authorisation settings.
Can anyone tell me what I am doing wrong?
I'm not sure is this will help https://developer.github.com/v3/guides/managing-deploy-keys/
private static void Main(string[] args)
{
var file = $"https://raw.githubusercontent.com/{username}/{repositoryName}/{branch}/{filePath}";
System.IO.File.WriteAllText($"c:\\{filePath}", GetFile(file));
System.Console.ReadKey();
}
public static string GetFile(string input)
{
var output = string.Empty;
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(input);
request.Headers.Add("Authorization", githubtoken);
request.AllowAutoRedirect = true;
var response = (HttpWebResponse)request.GetResponse();
using (var stream = new System.IO.MemoryStream())
{
response.GetResponseStream().CopyTo(stream);
output = System.Text.Encoding.ASCII.GetString(stream.ToArray());
}
response.Close();
return output;
}
EDIT:
So based on feedback (thanks Olivier), it seems that any use of the githubtoken I used returns either a 403 or 404. My token had read:packages & read:repo_hook and I thought that would be sufficient. I used the following link to show me how to create the token. Do I need anything else to access a private repo with a token?
Can I get access to this via username and password and if so how do I change the above to get a file?