public PhotoInfo GetPictureInfo(string fileId)
        {
            try
            {
                File file = service.Files.Get(fileId).Execute();

                string downloadUrl = file.WebContentLink;
                string thumbNailUrl = file.ThumbnailLink;

                int index = downloadUrl.LastIndexOf("&");
                string viewUrl = downloadUrl.Substring(0, index);

                var result = new PhotoInfo()
                {
                    Name = file.Title,
                    Url = viewUrl,
                };

                return result;
            }
            catch (Exception e)
            {
                return new PhotoInfo();
            }
        }
Beispiel #2
0
        public PhotoInfo GetPictureInfo(string fileId)
        {
            try
            {
                File file = service.Files.Get(fileId).Execute();

                string downloadUrl  = file.WebContentLink;
                string thumbNailUrl = file.ThumbnailLink;

                int    index   = downloadUrl.LastIndexOf("&");
                string viewUrl = downloadUrl.Substring(0, index);

                var result = new PhotoInfo()
                {
                    Name = file.Title,
                    Url  = viewUrl,
                };

                return(result);
            }
            catch (Exception e)
            {
                return(new PhotoInfo());
            }
        }
        private static void AddPhoto(HttpClient client, int albumId, string name, string url)
        {
            var newPhoto = new PhotoInfo()
            {
                Name = name,
                Url = url,
                PhotoAlbumId = albumId
            };

            HttpContent postContent = new StringContent(JsonConvert.SerializeObject(newPhoto));
            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

            var response = client.PostAsync("api/photos/create", postContent).Result;

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Picture {0} added!", name);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }