1

我可以访问 Versionone 的 Summer2013。我正在尝试使用 Json 示例通过新的 query.v1 访问它,该示例使用如下所示的客户端标头 cookie:

_client.Headers["Cookie"] = ".V1.Ticket.VersionOne.Web=" + ticket;

如何为 cookie 生成 .V1.Ticket.VersionOne.Web 票证?

Json 示例:https ://github.com/versionone/versionone-oauth2-examples/blob/master/csharp/YamlClient/Program.cs

注意:我已经通过这些说明生成了一个 OAuth 2 令牌,但它不包含票证。 https://community.versionone.com/Developers/Developer-Library/Documentation/API/Security/Oauth_2.0_Authentication/Using_OAuth_2.0_for_Web_Server_Applications

这是代码:

namespace V1Json
{
    class JsonClient
    {
        private readonly Uri _url;
        private readonly string _ticket;
        private WebClient _client;

        public JsonClient(string url, string ticket)
        {
            _url = new Uri(url);
            _ticket = ticket;
            _client = new WebClient { Encoding = Encoding.UTF8 };
           _client.Headers["Cookie"] = ".V1.Ticket.VersionOne.Web=" + ticket;
        }

        public List<List<dynamic>> GetResultSets(string querybody)
        {
            var resultbody = _client.UploadString(_url, "SEARCH", querybody);
            return JsonConvert.DeserializeObject<List<List<dynamic>>>(resultbody);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var url = "https://versionone-test.acme.com/summer13_demo/query.v1";
             var authTicket = "AAEAAGvqd3ylmW0FphkxxxHASSMoCrEa...";

            var client = new JsonClient(url, authTicket);
4

1 回答 1

0

我刚刚为您更新了该示例,包括使其与 Joe Koberg 最近创建的新 OAuth2Client 代码一起使用。

该示例的新版本包括已设置为在http://www14.v1host.com/v1sdktesting上针对我们的公共测试服务器工作的 stored_credentials.json 和 client_secrets.json 文件。要查看那里的项目或修改一些数据,请使用admin / admin登录。

它包括一个简单的 JsonClient,它利用 Newtonsoft 解析从服务器返回的 JSON。

它仍然位于https://github.com/versionone/versionone-oauth2-examples/blob/master/csharp/YamlClient/Program.cs

使用 JsonClient 示例如下所示:

IStorage credentials = new Storage.JsonFileStorage(
            "../../client_secrets.json", "../../stored_credentials.json");
        const string scopes = "query-api-1.0 apiv1";
        const string url = "https://www14.v1host.com/v1sdktesting/query.v1";

var client = new JsonClient(credentials, url, scopes);

const string queryBody = @"
from: Scope
select:
    - Name
    - Workitems.@Count
    - Workitems:PrimaryWorkitem.@Count
    - Workitems:PrimaryWorkitem[Estimate>'0'].@Count
    - Workitems:PrimaryWorkitem[Estimate='0'].@Count
    - Workitems:PrimaryWorkitem[Estimate>'0'].Estimate.@Sum
    - from: Workitems:PrimaryWorkitem[Estimate>'0']
      select:
        - Name
        - Estimate
";
        var resultSets = client.GetResultSets(queryBody).ToArray();

        foreach (var result in resultSets[0]) // Rember that query.v1 returns a resultSet of resultSets!
        {
            Console.WriteLine(result["Name"]);
            Console.WriteLine("Total # of workitems: " + result["Workitems.@Count"]);
            Console.WriteLine("Total # of Primary workitems: " + result["Workitems:PrimaryWorkitem.@Count"]);
            Console.WriteLine("Total # of Estimated Primary workitems: " +
                              result["Workitems:PrimaryWorkitem[Estimate>'0'].@Count"]);
            Console.WriteLine("Total # of Unestimated Primary workitems: " +
                              result["Workitems:PrimaryWorkitem[Estimate='0'].@Count"]);
            Console.WriteLine("Sum of all Estimated Primary workitems: " +
                              result["Workitems:PrimaryWorkitem[Estimate>'0'].Estimate.@Sum"]);
            foreach (var estimatedWorkitem in result["Workitems:PrimaryWorkitem[Estimate>'0']"])
            {
                Console.WriteLine(estimatedWorkitem["Name"] + " : " + estimatedWorkitem["Estimate"]);
            }
            Console.WriteLine("\n");
        }

        Console.Write("Press any key to exit...");
        Console.ReadLine();
    }
} 
于 2013-09-19T21:42:42.287 回答