/// <summary> /// Configure photo /// </summary> /// <param name="image">Photo to configure</param> /// <param name="uploadId">Upload id</param> /// <param name="caption">Caption</param> /// <returns></returns> private async Task <IResult <InstaMedia> > ConfigurePhotoAsync(InstaImage image, string uploadId, string caption) { try { var instaUri = UriCreator.GetMediaConfigureUri(); var androidVersion = AndroidVersion.FromString(_deviceInfo.FirmwareFingerprint.Split('/')[2].Split(':')[1]); if (androidVersion == null) { return(Result.Fail("Unsupported android version", (InstaMedia)null)); } var data = new JObject { { "_uuid", _deviceInfo.DeviceGuid.ToString() }, { "_uid", _user.LoggedInUser.Pk }, { "_csrftoken", _user.CsrfToken }, { "media_folder", "Camera" }, { "source_type", "4" }, { "caption", caption }, { "upload_id", uploadId }, { "device", new JObject { { "manufacturer", _deviceInfo.HardwareManufacturer }, { "model", _deviceInfo.HardwareModel }, { "android_version", androidVersion.VersionNumber }, { "android_release", androidVersion.APILevel } } }, { "edits", new JObject { { "crop_original_size", new JArray { image.Width, image.Height } }, { "crop_center", new JArray { 0.0, -0.0 } }, { "crop_zoom", 1 } } }, { "extra", new JObject { { "source_width", image.Width }, { "source_height", image.Height } } } }; var request = HttpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, data); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return(Result.UnExpectedResponse <InstaMedia>(response, json)); } var mediaResponse = JsonConvert.DeserializeObject <InstaMediaItemResponse>(json, new InstaMediaDataConverter()); var converter = ConvertersFabric.Instance.GetSingleMediaConverter(mediaResponse); return(Result.Success(converter.Convert())); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaMedia>(exception)); } }
private async Task <IResult <InstaMedia> > ConfigureVideoAsync(InstaVideo video, string uploadId, string caption) { try { var instaUri = UriCreator.GetMediaConfigureUri(); var androidVersion = AndroidVersion.FromString(_deviceInfo.FirmwareFingerprint.Split('/')[2].Split(':')[1]); if (androidVersion == null) { return(Result.Fail("Unsupported android version", (InstaMedia)null)); } var data = new JObject { { "caption", caption }, { "upload_id", uploadId }, { "source_type", "3" }, { "camera_position", "unknown" }, { "extra", new JObject { { "source_width", video.Width }, { "source_height", video.Height } } }, { "clips", new JArray { new JObject { { "length", 10.0 }, { "creation_date", DateTime.Now.ToString("yyyy-dd-MMTh:mm:ss-0fff") }, { "source_type", "3" }, { "camera_position", "back" } } } }, { "poster_frame_index", 0 }, { "audio_muted", false }, { "filter_type", "0" }, { "video_result", "deprecated" }, { "_csrftoken", _user.CsrfToken }, { "_uuid", _deviceInfo.DeviceGuid.ToString() }, { "_uid", _user.LoggedInUser.UserName } }; var request = HttpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, data); request.Headers.Host = "i.instagram.com"; var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return(Result.UnExpectedResponse <InstaMedia>(response, json)); } var success = await ExposeVideoAsync(uploadId); if (success.Succeeded) { return(Result.Success(success.Value)); } else { return(Result.Fail <InstaMedia>("Cannot expose media")); } } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaMedia>(exception)); } }