Get GitHub Rest API User info C# code

时间:2017-08-05 12:08:06

标签: c# api github

https://api.github.com/users/[UserName] can be accessed via browser. I get a Json result. But I want to retrieve the same information programmatically.

I'm using the below code, which is not working as expected. Please advice.

var credentials = 
string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", 
githubToken);
credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
client.DefaultRequestHeaders.Authorization = new 
AuthenticationHeaderValue("Basic", credentials);
var contents = 
client.GetStreamAsync("https://api.github.com/users/[userName]").Result;

As a result of the above code, I'm getting "Aggregate Exception".

How to achieve the requirement using c# code??? Please help

Note: Not expecting a solution with Octokit. Need proper c# code.

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。这是代码。

as?