Ejemplo n.º 1
0
        /// <summary>
        /// フォルダの新規作成
        /// https://dev.onedrive.com/items/create.htm
        /// </summary>
        /// <param name="parentID"></param>
        /// <param name="folder"></param>
        /// <returns></returns>
        public async Task <OnedriveItemMeta> CreateFolder(string folder, string parentID = null)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");

                HttpRequestMessage request = new HttpRequestMessage(
                    HttpMethod.Post,
                    (parentID == null) ?
                    new Uri(apistring + "/drive/root/children") :
                    new Uri(apistring + string.Format("/drive/items/{0}/children", parentID))
                    );


                request.Content = new StringContent("{\"name\": \"" + folder + "\",\"folder\": { }}", Encoding.UTF8, "application/json");

                var response = await httpClient.SendAsync(request);

                var responseText = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(responseText);

                OnedriveItemMeta item = JsonConvert.DeserializeObject <OnedriveItemMeta>(responseText);

                return(item);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// ROOTIDを取得
        /// </summary>
        /// <returns></returns>
        public async Task <string> getRootID()
        {
            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
                HttpRequestMessage request = new HttpRequestMessage(
                    HttpMethod.Get,
                    new Uri(apistring + "/drive/root")
                    );
                var response = await httpClient.SendAsync(request);

                Debug.WriteLine(response.Content.ReadAsStringAsync().Result);

                OnedriveItemMeta files = JsonConvert.DeserializeObject <OnedriveItemMeta>(response.Content.ReadAsStringAsync().Result);

                return(files.id);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// アイテムを取得
        /// </summary>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public async Task <OnedriveItemMeta> getItem(string itemID = null)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
                HttpRequestMessage request = new HttpRequestMessage(
                    HttpMethod.Get,
                    itemID == null ?
                    new Uri(apistring + "/drive/root?expand=children") :
                    new Uri(apistring + string.Format("/drive/items/{0}?expand=children", itemID))
                    );
                var response = await httpClient.SendAsync(request);

                OnedriveItemMeta item = JsonConvert.DeserializeObject <OnedriveItemMeta>(response.Content.ReadAsStringAsync().Result);

                return(item);
            }
        }