Example #1
0
        /// <summary>
        ///     Clear Recent searches
        /// </summary>
        public async Task <IResult <bool> > ClearRecentSearchsAsync()
        {
            try
            {
                var instaUri = InstaUriCreator.GetClearSearchHistoryUri();
                var data     = new JObject
                {
                    { "_csrftoken", user.CsrfToken }, { "_uuid", deviceInfo.DeviceGuid.ToString() }
                };
                var request  = httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, deviceInfo, data);
                var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.UnExpectedResponse <bool>(response, json));
                }

                var obj = JsonConvert.DeserializeObject <InstaDefault>(json);
                return(obj.Status == "ok" ? Result.Success(true) : Result.UnExpectedResponse <bool>(response, json));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(bool), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <bool>(exception));
            }
        }
Example #2
0
        /// <summary>
        ///     Adds items to collection asynchronous.
        /// </summary>
        /// <param name="collectionId">Collection identifier.</param>
        /// <param name="mediaIds">Media id list.</param>
        public async Task <IResult <InstaCollectionItem> > AddItemsToCollectionAsync(
            long collectionId,
            params string[] mediaIds)
        {
            InstaUserAuthValidator.Validate(userAuthValidate);
            try
            {
                if (mediaIds?.Length < 1)
                {
                    return(Result.Fail <InstaCollectionItem>("Provide at least one media id to add to collection"));
                }

                var editCollectionUri = InstaUriCreator.GetEditCollectionUri(collectionId);

                var data = new JObject
                {
                    { "module_name", InstaApiConstants.FeedSavedAddToCollectionModule },
                    { "added_media_ids", JsonConvert.SerializeObject(mediaIds) },
                    { "radio_type", "wifi-none" },
                    { "_uuid", deviceInfo.DeviceGuid.ToString() },
                    { "_uid", user.LoggedInUser.Pk },
                    { "_csrftoken", user.CsrfToken }
                };

                var request =
                    httpHelper.GetSignedRequest(HttpMethod.Get, editCollectionUri, deviceInfo, data);
                var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.UnExpectedResponse <InstaCollectionItem>(response, json));
                }

                var newCollectionResponse = JsonConvert.DeserializeObject <InstaCollectionItemResponse>(json);
                var converter             = InstaConvertersFabric.Instance.GetCollectionConverter(newCollectionResponse);
                return(Result.Success(converter.Convert()));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(InstaCollectionItem), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <InstaCollectionItem>(exception));
            }
        }
        /// <summary>
        ///     Comment media
        /// </summary>
        /// <param name="mediaId">Media id</param>
        /// <param name="text">Comment text</param>
        public async Task <IResult <InstaComment> > CommentMediaAsync(string mediaId, string text)
        {
            InstaUserAuthValidator.Validate(userAuthValidate);
            try
            {
                var instaUri   = InstaUriCreator.GetPostCommetUri(mediaId);
                var breadcrumb = InstaCryptoHelper.GetCommentBreadCrumbEncoded(text);
                var fields     = new Dictionary <string, string>
                {
                    { "user_breadcrumb", breadcrumb },
                    { "idempotence_token", Guid.NewGuid().ToString() },
                    { "_uuid", deviceInfo.DeviceGuid.ToString() },
                    { "_uid", user.LoggedInUser.Pk.ToString() },
                    { "_csrftoken", user.CsrfToken },
                    { "comment_text", text },
                    { "containermodule", "comments_feed_timeline" },
                    { "radio_type", "wifi-none" }
                };
                var request =
                    httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, deviceInfo, fields);
                var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.UnExpectedResponse <InstaComment>(response, json));
                }

                var commentResponse = JsonConvert.DeserializeObject <InstaCommentResponse>(
                    json,
                    new InstaCommentDataConverter());
                var converter = InstaConvertersFabric.Instance.GetCommentConverter(commentResponse);
                return(Result.Success(converter.Convert()));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(InstaComment), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <InstaComment>(exception));
            }
        }
        private async Task <IResult <InstaTvChannel> > GetChannel(InstaTvChannelType?channelType,
                                                                  long?userId,
                                                                  PaginationParameters paginationParameters)
        {
            try
            {
                var instaUri = InstaUriCreator.GetIgtvChannelUri();
                var data     = new JObject
                {
                    { "_uuid", deviceInfo.DeviceGuid.ToString() },
                    { "_uid", user.LoggedInUser.Pk.ToString() },
                    { "_csrftoken", user.CsrfToken }
                };
                if (channelType != null)
                {
                    data.Add("id", channelType.Value.GetRealChannelType());
                }
                else
                {
                    data.Add("id", $"user_{userId}");
                }

                if (paginationParameters != null && !string.IsNullOrEmpty(paginationParameters.NextMaxId))
                {
                    data.Add("max_id", paginationParameters.NextMaxId);
                }

                var request  = httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, deviceInfo, data);
                var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.UnExpectedResponse <InstaTvChannel>(response, json));
                }

                var obj = JsonConvert.DeserializeObject <InstaTvChannelResponse>(json);

                return(Result.Success(InstaConvertersFabric.Instance.GetTvChannelConverter(obj).Convert()));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(InstaTvChannel), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <InstaTvChannel>(exception));
            }
        }
Example #5
0
        /// <summary>
        ///     Add button to your business account
        /// </summary>
        /// <param name="businessPartner">
        ///     Desire partner button (Use
        ///     <see cref="IBusinessProcessor.GetBusinessPartnersButtonsAsync" /> to get business buttons(instagram partner) list!)
        /// </param>
        /// <param name="uri">Uri (related to Business partner button)</param>
        public async Task <IResult <InstaBusinessUser> > AddOrChangeBusinessButtonAsync(
            InstaBusinessPartner businessPartner,
            Uri uri)
        {
            InstaUserAuthValidator.Validate(userAuthValidate);
            try
            {
                if (businessPartner == null)
                {
                    return(Result.Fail <InstaBusinessUser>("Business partner cannot be null"));
                }

                if (uri == null)
                {
                    return(Result.Fail <InstaBusinessUser>("Uri related to business partner cannot be null"));
                }

                var validateUri = await ValidateUrlAsync(businessPartner, uri).ConfigureAwait(false);

                if (!validateUri.Succeeded)
                {
                    return(Result.Fail <InstaBusinessUser>(validateUri.Info.Message));
                }

                var instaUri = InstaUriCreator.GetUpdateBusinessInfoUri();

                var data = new JObject
                {
                    { "ix_url", uri.ToString() },
                    { "ix_app_id", businessPartner.AppId },
                    { "is_call_to_action_enabled", "1" },
                    { "_csrftoken", user.CsrfToken },
                    { "_uid", user.LoggedInUser.Pk.ToString() },
                    { "_uuid", deviceInfo.DeviceGuid.ToString() }
                };

                var request =
                    httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, deviceInfo, data);
                var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false);

                var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.UnExpectedResponse <InstaBusinessUser>(response, json));
                }

                var obj = JsonConvert.DeserializeObject <InstaBusinessUserContainerResponse>(json);

                return(Result.Success(InstaConvertersFabric.Instance.GetBusinessUserConverter(obj).Convert()));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(InstaBusinessUser), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <InstaBusinessUser>(exception));
            }
        }