我正在尝试获取 VSTS 中项目的完整列表。使用此代码为我提供了前 100 个项目,但我找不到指定/要求更多项目的方法
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://{accountname}.visualstudio.com/DefaultCollection");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", {credentials});
HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=1.0").Result;
if (response.IsSuccessStatusCode)
{
responseString = response.Content.ReadAsStringAsync().Result.ToString();
}
else
{
//failed
}
}
// Convert responseString into a json Object
RootObj jsonObj = JsonConvert.DeserializeObject<RootObj>(responseString);
Console.WriteLine("Found " + jsonObj.Count + " projects");
//Do stuff
foreach (var obj in jsonObj.Value)
{
//foreach project...
}
我知道有 100 多个项目,但它只会每次返回那么多。有什么方法可以将“TOP 1000”合并到请求中吗?该语法是什么?谢谢
现在可以工作了,我将其中一行改为:
HttpResponseMessage response = client.GetAsync("_apis/projects?$top=250&stateFilter=All&api-version=1.0").Result;
最佳答案
我很惊讶 API 文档不完整。您可以指定一个 $top
参数。
例如:_apis/projects?$top=250&version=1.0
关于c# - VSTS - 使用 API 获取所有项目的列表,而不仅仅是前 100 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50688102/