예제 #1
0
        /// <summary>
        /// Sends an image file to Twitter to replace user image.
        /// </summary>
        /// <param name="image">byte array of image to upload</param>
        /// <param name="fileName">name to pass to Twitter for the file</param>
        /// <param name="imageType">type of image: must be one of jpg, gif, or png</param>
        /// <param name="includeEntities">Set to false to not include entities. (default: true)</param>
        /// <param name="skipStatus">Don't include status with response.</param>
        /// <returns>User with new image info</returns>
        public async Task <User> UpdateAccountImageAsync(byte[] image, string fileName, string imageType, bool includeEntities, bool skipStatus, CancellationToken cancelToken = default(CancellationToken))
        {
            var accountUrl = BaseUrl + "account/update_profile_image.json";

            if (image == null || image.Length == 0)
            {
                throw new ArgumentException("image is required.", "image");
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("fileName is required.", "fileName");
            }

            if (string.IsNullOrWhiteSpace(imageType))
            {
                throw new ArgumentException("imageType is required.", "imageType");
            }

            var reqProc    = new UserRequestProcessor <User>();
            var parameters = new Dictionary <string, string>
            {
                { "include_entities", includeEntities.ToString().ToLower() },
                { "skip_status", skipStatus.ToString().ToLower() }
            };

            string name          = "image";
            string imageMimeType = "image/" + imageType;

            RawResult = await TwitterExecutor.PostImageAsync(accountUrl, parameters, image, name, fileName, imageMimeType, cancelToken : cancelToken).ConfigureAwait(false);

            return(reqProc.ProcessActionResult(RawResult, UserAction.SingleUser));
        }