示例#1
0
文件: API.cs 项目: Yecats/GW2Helper
        /// <summary>
        /// Gets the account information based on the API key
        /// </summary>
        /// <param name="key">Account API Key</param>
        /// <returns></returns>
        public Account GetAccount(string key)
        {
            Account accountInfo = new Account();
            var client = new HttpClient();
            var request = new HttpRequestMessage()
            {
                RequestUri = new Uri(_account + "?access_token=" + key),
                Method = HttpMethod.Get
            };

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));

            var task = client.SendAsync(request).ContinueWith((taskwithmsg) =>
            {
                var response = taskwithmsg.Result;
                var jsonTask = response.Content.ReadAsStringAsync();
                accountInfo = JsonConvert.DeserializeObject<Account>(jsonTask.Result);
            });
            task.Wait();

            return accountInfo;
        }
示例#2
0
        public bool ValidateAPIKey()
        {
            _accountInformation = API.Instance.GetAccount(APIKey);
            _tokenInformation = API.Instance.GetTokenInfo(APIKey);

            return true;
        }