Пример #1
0
        private async void Restart()
        {
            Log("Restarting realtime server");
            Shutdown();
            if (AppIsInBackground)
            {
                return;
            }
            await Task.Delay(TimeSpan.FromSeconds(3));

            if (Running)
            {
                return;
            }
            try
            {
                var inbox = await _instaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(1));

                if (inbox.Succeeded)
                {
                    SeqId      = inbox.Value.SeqId;
                    SnapshotAt = inbox.Value.SnapshotAt;
                }
            }
            catch { }
            try
            {
                await StartFresh();

                NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged;
            }
            catch { }
        }
Пример #2
0
        public async Task <IEnumerable <InstaDirectInboxItemWrapper> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = new CancellationToken())
        {
            // Without ThreadId we cant fetch thread items.
            if (string.IsNullOrEmpty(ThreadId) || !(HasOlder ?? true))
            {
                return(new List <InstaDirectInboxItemWrapper>(0));
            }
            var pagesToLoad = pageSize / 20;

            if (pagesToLoad < 1)
            {
                pagesToLoad = 1;
            }
            var pagination = PaginationParameters.MaxPagesToLoad(pagesToLoad);

            pagination.StartFromMaxId(OldestCursor);
            var result = await _instaApi.GetThreadAsync(ThreadId, pagination);

            if (result.Status != ResultStatus.Succeeded || result.Value.Items == null || result.Value.Items.Count == 0)
            {
                return(new List <InstaDirectInboxItemWrapper>(0));
            }
            UpdateExcludeItemList(result.Value);
            var wrappedItems = result.Value.Items.Select(x => new InstaDirectInboxItemWrapper(x, this, _instaApi)).ToList();

            DecorateItems(wrappedItems);
            return(wrappedItems);
        }
Пример #3
0
        private static async void GetUserInfo(string input)
        {
            var userToSerch = input;

            var user = await api.UserProcessor.GetUserAsync(userToSerch);

            if (user.Succeeded)
            {
                await botClient.SendChatActionAsync(chatId, ChatAction.Typing);

                userMedia = await api.UserProcessor.GetUserMediaAsync(userToSerch, PaginationParameters.MaxPagesToLoad(1));

                if (!userMedia.Succeeded)
                {
                    await botClient.SendTextMessageAsync(chatId, $"{userMedia.Info.Message}");

                    return;
                }

                var averageLikes = GetAverageLikes();

                await botClient.SendPhotoAsync(chatId, user.Value.ProfilePicture);

                await botClient.SendTextMessageAsync(chatId,
                                                     $"User : {user.Value.UserName}{Environment.NewLine}" +
                                                     $"Followers Count : {user.Value.FollowersCount}{Environment.NewLine}" +
                                                     $"Average likes for the last 6 posts : {averageLikes}");
            }
            else
            {
                await botClient.SendTextMessageAsync(chatId, "User Not Found");
            }
        }
Пример #4
0
        public static async void Like(string userExp, string userName, string password)
        {
            user          = new UserSessionData();
            user.UserName = userName;
            user.Password = password;

            api = InstaApiBuilder.CreateBuilder()
                  .SetUser(user)
                  .UseLogger(new DebugLogger(LogLevel.Exceptions))
                  //.SetRequestDelay(TimeSpan.FromSeconds(1))
                  .Build();
            var loginRequest = await api.LoginAsync();

            IResult <InstaUser> userSearch = await api.GetUserAsync(userExp);

            IResult <InstaMediaList> media = await api.GetUserMediaAsync(userExp, PaginationParameters.MaxPagesToLoad(5));

            var mediaList       = media.Value;
            int count_mediaList = mediaList.ToArray().Length;

            for (int i = 0; i < count_mediaList; i++)
            {
                var res = await api.LikeMediaAsync(mediaList[i].InstaIdentifier);

                string result = res.Succeeded.ToString();
            }
        }
Пример #5
0
        public async Task ExploreLikeHashtag(string hashtag, int pages)
        {
            int counter = 0;
            var tagFeed = await InstaApi.FeedProcessor.GetTagFeedAsync(hashtag, PaginationParameters.MaxPagesToLoad(pages));

            if (tagFeed.Succeeded)
            {
                foreach (var media in tagFeed.Value.Medias)
                {
                    Console.WriteLine(media.Pk);
                    Console.WriteLine(media.Code);
                    Console.WriteLine(media.LikesCount);
                    Console.WriteLine(media.User);
                    Console.WriteLine("===================");
                    var likeResult = await InstaApi.MediaProcessor.LikeMediaAsync(media.InstaIdentifier);

                    var resultString = likeResult.Value ? "liked" : "not liked";
                    if (likeResult.Value)
                    {
                        counter++;
                    }
                    Console.WriteLine($"Media {media.Code} {resultString}");
                }
                Console.WriteLine("Liked: " + counter + " medias");
            }
        }
Пример #6
0
 public RecentActivity(uint maxCount, Func <int, T> generator)
 {
     HasMoreItems = true;
     _generator   = generator;
     _maxCount    = maxCount;
     pagination   = PaginationParameters.MaxPagesToLoad(1);
 }
Пример #7
0
 public GenerateDirectsList(uint maxCount, Func <int, T> generator)
 {
     HasMoreItems = true;
     _generator   = generator;
     _maxCount    = maxCount;
     pagination   = PaginationParameters.MaxPagesToLoad(1);
 }
Пример #8
0
        private async void GetFeedButtonClick(object sender, EventArgs e)
        {
            // Note2: A RichTextBox control added to show you some of feeds.

            if (InstaApi == null)
            {
                MessageBox.Show("Login first.");
            }
            if (!InstaApi.IsUserAuthenticated)
            {
                MessageBox.Show("Login first.");
            }

            var x = await InstaApi.GetExploreFeedAsync(PaginationParameters.MaxPagesToLoad(1));

            Debug.WriteLine("Explore Feeds Result: " + x.Succeeded);

            if (x.Succeeded)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var media in x.Value.Medias)
                {
                    sb.AppendLine(DebugUtils.PrintMedia("Feed media", media));
                }
                RtBox.Text    = sb.ToString();
                RtBox.Visible = true;
                Size          = ChallengeSize;
            }
        }
Пример #9
0
        public async Task <IEnumerable <InstaDirectInboxThreadWrapper> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = new CancellationToken())
        {
            var pagesToLoad = pageSize / 20;

            if (pagesToLoad < 1)
            {
                pagesToLoad = 1;
            }
            var pagination = PaginationParameters.MaxPagesToLoad(pagesToLoad);

            pagination.StartFromMaxId(OldestCursor);
            var result = await _instaApi.GetInboxAsync(pagination);

            InboxContainer container;

            if (result.Status == ResultStatus.Succeeded)
            {
                container = result.Value;
                if (_firstTime)
                {
                    _firstTime = false;
                    FirstUpdated?.Invoke(container.SeqId, container.SnapshotAt);
                }
            }
            else
            {
                return(new List <InstaDirectInboxThreadWrapper>(0));
            }
            UpdateExcludeThreads(container);
            return(container.Inbox.Threads.Select(x => new InstaDirectInboxThreadWrapper(x, _instaApi)));
        }
Пример #10
0
        public async Task <IReadOnlyCollection <SocialMediaImage> > FetchInstagramImages(Guid chapterId)
        {
            ChapterLinks links = await _chapterRepository.GetChapterLinks(chapterId);

            if (links == null)
            {
                throw new OdkNotFoundException();
            }

            if (string.IsNullOrEmpty(links.InstagramName))
            {
                return(new SocialMediaImage[0]);
            }

            IInstaApi api = await OpenApi();

            PaginationParameters     paginationParameters = PaginationParameters.MaxPagesToLoad(1);
            IResult <InstaMediaList> media = await api.GetUserMediaAsync(links.InstagramName, paginationParameters);

            return(media.Value
                   .OrderByDescending(x => x.DeviceTimeStamp)
                   .Where(x => x.Images.Count > 0)
                   .Select(x => new SocialMediaImage
            {
                Caption = x.Caption.Text,
                ImageUrl = x.Images.OrderBy(img => img.Width).First().URI,
                Url = $"https://www.instagram.com/p/{x.Code}"
            })
                   .ToArray());
        }
Пример #11
0
        public List <string> DoWork(int id)
        {
            var pp = PaginationParameters.MaxPagesToLoad(5);
            var a  = Program.instants.First().InstaApi.UserProcessor.GetUserMediaAsync("ikasimoff", pp).GetAwaiter().GetResult();

            return(a.Value.Select(i => i.Images[0].URI).ToList());
        }
Пример #12
0
        private async void Restart()
        {
            this.Log("Restarting realtime server");
            NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChanged;
            _runningTokenSource?.Cancel();
            try
            {
                _inboundReader?.Dispose();
                _outboundWriter?.DetachStream();
                _outboundWriter?.Dispose();
            }
            catch { }
            await Task.Delay(TimeSpan.FromSeconds(3));

            if (Running)
            {
                return;
            }
            try
            {
                var inbox = await _instaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(1));

                if (inbox.Succeeded)
                {
                    SeqId      = inbox.Value.SeqId;
                    SnapshotAt = inbox.Value.SnapshotAt;
                }
            }
            catch { }
            await StartFresh();

            NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged;
        }
Пример #13
0
        public async Task Start(int seqId, DateTime snapshotAt)
        {
            if (!_instaApi.IsUserAuthenticated || Running)
            {
                return;
            }

            if (seqId == 0)
            {
                var inbox = await _instaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(1));

                if (inbox.Succeeded)
                {
                    SeqId      = inbox.Value.SeqId;
                    SnapshotAt = inbox.Value.SnapshotAt;
                }
                else
                {
                    return;
                }
            }
            SeqId      = seqId;
            SnapshotAt = snapshotAt;
            try
            {
                await StartFresh().ConfigureAwait(false);
            }
            catch (Exception)
            {
                await StartFresh().ConfigureAwait(false);
            }
        }
Пример #14
0
        private async void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var resentActivity =
                ApiManage.instaApi.UserProcessor.GetRecentActivityFeedAsync(PaginationParameters.MaxPagesToLoad(1));



            progressBar1.Invoke((MethodInvoker) delegate
            {
                progressBar1.Maximum = resentActivity.Result.Value.Items.Count;
            });

            for (int i = 0; i < resentActivity.Result.Value.Items.Count; i++)
            {
                dgvActivity.Invoke((MethodInvoker) delegate
                {
                    dgvActivity.Rows.Add(!string.IsNullOrEmpty(resentActivity.Result.Value.Items[i].Text) ? resentActivity.Result.Value.Items[i].Text :
                                         "ایستات الکی لاک میزنه والا ",
                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Year} / " +
                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Month} / " +
                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Day}",

                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Second} : " +
                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Minute} : " +
                                         $"{resentActivity.Result.Value.Items[i].TimeStamp.Hour}");
                });
                backgroundWorker1.ReportProgress(i + 1);
            }
        }
Пример #15
0
        /// <summary>
        ///     Get your collections
        /// </summary>
        /// <param name="paginationParameters">Pagination parameters: next max id and max amount of pages to load</param>
        /// <returns>
        ///     <see cref="T:InstagramApiSharp.Classes.Models.InstaCollections" />
        /// </returns>
        public async Task <IResult <InstaCollections> > GetCollectionsAsync(PaginationParameters paginationParameters)
        {
            InstaUserAuthValidator.Validate(userAuthValidate);
            try
            {
                if (paginationParameters == null)
                {
                    paginationParameters = PaginationParameters.MaxPagesToLoad(1);
                }

                InstaCollections Convert(InstaCollectionsResponse instaCollectionsResponse)
                {
                    return(InstaConvertersFabric.Instance.GetCollectionsConverter(instaCollectionsResponse).Convert());
                }

                var collections = await GetCollections(paginationParameters).ConfigureAwait(false);

                if (!collections.Succeeded)
                {
                    return(Result.Fail(collections.Info, default(InstaCollections)));
                }

                var collectionsResponse = collections.Value;
                paginationParameters.NextMaxId = collectionsResponse.NextMaxId;
                var pagesLoaded = 1;

                while (collectionsResponse.MoreAvailable &&
                       !string.IsNullOrEmpty(collectionsResponse.NextMaxId) &&
                       pagesLoaded < paginationParameters.MaximumPagesToLoad)
                {
                    var nextCollection = await GetCollections(paginationParameters).ConfigureAwait(false);

                    if (!nextCollection.Succeeded)
                    {
                        return(Result.Fail(nextCollection.Info, Convert(nextCollection.Value)));
                    }

                    collectionsResponse.NextMaxId           = paginationParameters.NextMaxId = nextCollection.Value.NextMaxId;
                    collectionsResponse.MoreAvailable       = nextCollection.Value.MoreAvailable;
                    collectionsResponse.AutoLoadMoreEnabled = nextCollection.Value.AutoLoadMoreEnabled;
                    collectionsResponse.Status = nextCollection.Value.Status;
                    collectionsResponse.Items.AddRange(nextCollection.Value.Items);
                    pagesLoaded++;
                }

                var converter = InstaConvertersFabric.Instance.GetCollectionsConverter(collectionsResponse);

                return(Result.Success(converter.Convert()));
            }
            catch (HttpRequestException httpException)
            {
                logger?.LogError(httpException, "Error");
                return(Result.Fail(httpException, default(InstaCollections), ResponseType.NetworkProblem));
            }
            catch (Exception exception)
            {
                logger?.LogError(exception, "Error");
                return(Result.Fail <InstaCollections>(exception));
            }
        }
Пример #16
0
        private async Task <IResult <InstaPlaceListResponse> > SearchPlaces(double latitude,
                                                                            double longitude,
                                                                            string query,
                                                                            PaginationParameters paginationParameters)
        {
            try
            {
                if (paginationParameters == null)
                {
                    paginationParameters = PaginationParameters.MaxPagesToLoad(1);
                }

                var instaUri = UriCreator.GetSearchPlacesUri(InstaApiConstants.TIMEZONE_OFFSET,
                                                             latitude, longitude, query, paginationParameters.NextId);

                var request  = _httpHelper.GetDefaultRequest(HttpMethod.Get, instaUri, _deviceInfo);
                var response = await _httpRequestProcessor.SendAsync(request);

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

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

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(Result.Fail <InstaPlaceListResponse>(obj.Message));
                }

                return(Result.Success(obj));
            }
            catch (Exception exception)
            {
                _logger?.LogException(exception);
                return(Result.Fail <InstaPlaceListResponse>(exception));
            }
        }
Пример #17
0
        public async Task Execute(Queue queue, InstaBotContext db)
        {
            var  allGroups     = queue.LoadId.Split(' ');
            bool isMediaPosted = false;

            foreach (var group in allGroups)
            {
                var instaMediaList = await _instaApi.GetUserMediaAsync(group, PaginationParameters.MaxPagesToLoad(0));

                InstaMedia firstMedia = instaMediaList?.Value?.FirstOrDefault();

                if (firstMedia != null && firstMedia.MediaType != InstaMediaType.Video && !IsAlreadyPosted(firstMedia.InstaIdentifier, queue.LoginData.Name, db))
                {
                    var caption = GetCaption(queue, firstMedia);
                    isMediaPosted = await PostMediaAsync(firstMedia, caption);
                }

                if (isMediaPosted || group.Equals(allGroups.LastOrDefault()))
                {
                    await UpdateQueueLastActivityAsync(queue, db);
                    await AddFinishedQueuToHistory(firstMedia.InstaIdentifier, queue, db);

                    Console.WriteLine($"PostMediaExecutor for {queue.LoginData.Name}");
                    return;
                }
            }
        }
Пример #18
0
        public override async Task Execute()
        {
            this.Logger.Log("Executing repost module...");

            if (this.Targets.Count <= 0 || this.Comments.Count <= 0)
            {
                throw new Exception("Not enough targets / comments");
            }

            var comment = this.Comments.ChooseRandom();
            var target  = this.Targets.ChooseRandom();

            this.Logger.Log($"Commenting {target} - {comment}...");

            var posts = await this.User.Api.UserProcessor.GetUserMediaAsync(target,
                                                                            PaginationParameters.MaxPagesToLoad(1));

            if (!posts.Succeeded || posts.Value.Count <= 0)
            {
                throw new Exception("Couldn't fetch user posts!");
            }

            this.Logger.Log($"Commenting...");
            var res = await this.User.Api.CommentProcessor.CommentMediaAsync(posts.Value.First().InstaIdentifier,
                                                                             comment);

            this.Logger.Log($"Done! (succeed? {res.Succeeded})");
        }
Пример #19
0
 public PictureLibarys(uint maxCount, Func <int, T> generator)
 {
     HasMoreItems = true;
     _generator   = generator;
     _maxCount    = maxCount;
     pagination   = PaginationParameters.MaxPagesToLoad(1);
 }
Пример #20
0
        async void LoadPage()
        {
            _ProgressBar.IsIndeterminate = true;

            var strs = await AppCore.InstaApi.GetExploreFeedAsync(PaginationParameters.MaxPagesToLoad(1));

            //

            //
            Live.DataContext = strs.Value.StoryTray.TopLive;

            StoriesList.ItemsSource = strs.Value.StoryTray.Tray.OrderBy(x => x.SeenRankedPosition != 0);

            ListVideos.DataContext = strs.Value.Channel;
            if (ExplorePageItemssource != null)
            {
                ExplorePageItemssource.CollectionChanged -= HomePageItemssource_CollectionChanged;
            }

            ExplorePageItemssource = new GenerateExplorePage <InstaMedia>(100000, (count) => new InstaMedia());

            ExplorePageItemssource.CollectionChanged += HomePageItemssource_CollectionChanged;

            mylist.ItemsSource = ExplorePageItemssource;

            _ProgressBar.IsIndeterminate = false;
            var sv = FindChildOfType <ScrollViewer>(mylist);

            sv.ViewChanged += Sv_ViewChanged;
        }
        public async Task <InstaMediaList> GetLastMedia(string userName)
        {
            var userMedia = await this.Instagram.UserProcessor.GetUserMediaAsync(
                userName, PaginationParameters.MaxPagesToLoad(1));

            return(userMedia.Value);
        }
Пример #22
0
        public List <ApplicationUser> GetUserFollowersByUsername(string username)
        {
            if (_instaApi == null)
            {
                throw new NullReferenceException();
            }

            List <ApplicationUser> followersResult = new List <ApplicationUser>();

            Task <IResult <InstaUserShortList> > getFollowersTask = Task.Run(
                () => _instaApi.UserProcessor.GetUserFollowersAsync(username, PaginationParameters.MaxPagesToLoad(MAX_PAGES_TO_LOAD)));

            getFollowersTask.Wait();

            IResult <InstaUserShortList> followers = getFollowersTask.Result;;

            if (followers.Succeeded)
            {
                Parallel.ForEach(followers.Value, (follower) =>
                {
                    ApplicationUser newUser = new ApplicationUser
                    {
                        InstagramPK = follower.Pk.ToString(),
                        Username    = follower.UserName
                    };

                    followersResult.Add(newUser);
                });
            }

            return(followersResult);
        }
Пример #23
0
        public async Task DirectAnswerMessage(string username, string message)
        {
            try
            {
                var inbox = await InstaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(1));

                if (!inbox.Succeeded)
                {
                    ExceptionUtils.Throw(Error.E_ACC_DIRECT, ErrorsContract.ACC_DIRECT_THREADS + inbox.Info.Message);
                }
                var desireThread = inbox.Value.Inbox.Threads
                                   .Find(u => u.Users.FirstOrDefault().UserName.ToLower() == username);
                var requestedThreadId = desireThread.ThreadId;
                var directText        = await InstaApi.MessagingProcessor.SendDirectTextAsync(null, requestedThreadId, message);

                if (!directText.Succeeded)
                {
                    ExceptionUtils.Throw(Error.E_ACC_DIRECT, ErrorsContract.ACC_DIRECT_SEND + directText.Info.Message);
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.Throw(Error.E_ACC_DIRECT, ErrorsContract.ACC_DIRECT_SEND_FAIL + ex.Message);
            }
        }
Пример #24
0
        public async Task <List <InstagramPost> > GetUserPostsByPrimaryKeyAsync(string primaryKey)
        {
            if (_instaApi == null)
            {
                throw new NullReferenceException();
            }

            long pk = Convert.ToInt64(primaryKey);
            List <InstagramPost> posts      = new List <InstagramPost>();
            PaginationParameters pageParams = PaginationParameters.MaxPagesToLoad(MAX_PAGES_TO_LOAD);

            IResult <InstaMediaList> mediaList = await _instaApi.UserProcessor.GetUserMediaByIdAsync(pk, pageParams);

            if (mediaList.Succeeded)
            {
                Parallel.ForEach(mediaList.Value, media =>
                {
                    InstagramPost post   = new InstagramPost();
                    post.CountOfComments = Convert.ToInt32(media.CommentsCount);
                    post.Commenters      = GetPostCommenters(media);
                    post.CountOfLikes    = Convert.ToInt32(media.LikesCount);
                    post.Likers          = GetPostLikers(media);
                    post.MediaFileUri    = GetUri(media);
                    posts.Add(post);
                });
            }

            return(posts);
        }
Пример #25
0
        public async Task DirectCheckMessages()
        {
            var inbox = await InstaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(5));

            if (inbox.Value.Inbox.UnseenCount != 0)
            {
                Console.WriteLine("Unreaded messages: " + inbox.Value.Inbox.UnseenCount);
                Messages msg = new Messages(userSession.UserName);
                foreach (var thread in inbox.Value.Inbox.Threads)
                {
                    if (thread.HasUnreadMessage)
                    {
                        bool readed  = false;
                        var  threads = await InstaApi.MessagingProcessor.GetDirectInboxThreadAsync(thread.ThreadId, PaginationParameters.MaxPagesToLoad(20));

                        foreach (var item in threads.Value.Items.AsEnumerable().Reverse())
                        {
                            Console.WriteLine(item.Text);
                            msg.StackMessage(thread.Title, thread.VieweId, item.UserId.ToString(), item.ItemId, item.Text, item.TimeStamp);
                            if (!readed)
                            {
                                var mark = await InstaApi.MessagingProcessor.MarkDirectThreadAsSeenAsync(thread.ThreadId, item.ItemId);

                                readed = true;
                            }
                        }
                    }
                }
                msg.WriteMessages();
            }
            else
            {
                Console.WriteLine("There are no unreaded messages");
            }
        }
Пример #26
0
        public async Task <List <ApplicationUser> > GetUserSubscriptionsByUsernameAsync(string username)
        {
            if (_instaApi == null)
            {
                throw new NullReferenceException();
            }

            List <ApplicationUser> subscriptionsResult = new List <ApplicationUser>();

            PaginationParameters pageParams = PaginationParameters.MaxPagesToLoad(MAX_PAGES_TO_LOAD);

            IResult <InstaUserShortList> subscriptions = await _instaApi.UserProcessor.GetUserFollowingAsync(username, pageParams);

            if (subscriptions.Succeeded)
            {
                Parallel.ForEach(subscriptions.Value, (profile) =>
                {
                    ApplicationUser newProfile = new ApplicationUser
                    {
                        InstagramPK = profile.Pk.ToString(),
                        Username    = profile.UserName
                    };

                    subscriptionsResult.Add(newProfile);
                });
            }

            return(subscriptionsResult);
        }
Пример #27
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            if (!HasMoreItems && !refresh)
            {
                IsLoading = false;
                return;
            }
            try
            {
                if (refresh)
                {
                    Pagination = PaginationParameters.MaxPagesToLoad(1);
                }
                else
                {
                }
                var result = await InstaApi.StoryProcessor.GetStoryQuizParticipantsAsync(StoryItem.Id, StoryQuizStickerItem.QuizId.ToString(),
                                                                                         Pagination);

                FirstRun = false;
                Pagination.MaximumPagesToLoad = 1;
                if (!result.Succeeded)
                {
                    IsLoading = false;
                    if (result.Value == null || result.Value.Participants?.Count == 0)
                    {
                        Hide(refresh);
                        return;
                    }
                }

                HasMoreItems = result.Value.MoreAvailable ?? false;

                Pagination.NextMaxId = result.Value.MaxId;
                if (refresh)
                {
                    Items.Clear();
                }
                if (result.Value.Participants?.Count > 0)
                {
                    var obj = result.Value.Participants[0];
                    for (int i = 0; i < result.Value.Participants.Count; i++)
                    {
                        var index = result.Value.Participants[i].Answer;
                        result.Value.Participants[i].AnswerText = StoryQuizStickerItem.Tallies[index].Text;
                    }
                    Items.AddRange(result.Value.Participants);
                }
                await Task.Delay(1000);

                IsLoading = false;
            }
            catch (Exception ex)
            {
                FirstRun      =
                    IsLoading = false;
                ex.PrintException("Participants.LoadMoreItemsAsync");
            }
            Hide(refresh);
        }
Пример #28
0
        public async void SetThread(InstaDirectInboxThread directInboxThread)
        {
            CurrentThread = directInboxThread;

            try
            {
                Items.Clear();
                if (directInboxThread.Items.Count == 0)
                {
                    var result = await InstaApi.MessagingProcessor
                                 .GetDirectInboxThreadAsync(directInboxThread.ThreadId,
                                                            PaginationParameters.MaxPagesToLoad(1), Views.Direct.InboxView.Current?.InboxVM?.SeqId ?? 0);

                    if (result.Succeeded)
                    {
                        directInboxThread.Items.AddRange(result.Value.Items);
                    }
                }

                var items = directInboxThread.Items;
                items.Reverse();
                items.ForEach(x => Items.Insert(0, x));
            }
            catch { }
            //if (CurrentThread.Items?.Count > 0)
            //{
            //    CurrentThread.Items.Reverse();
            //    CurrentThread.Items.ForEach(x => Items.Add(x));
            //    if (!any)
            //        ListView.ScrollIntoView(Items[Items.Count - 1]);
            //}
        }
Пример #29
0
        public async void TotalDePublicacoes(string username, IInstaApi api)
        {
            IResult <InstaUser> userSearch = await api.GetUserAsync(username);

            Console.WriteLine($"USER:{userSearch.Value.FullName}\n\tFollowers: {userSearch.Value.FollowersCount}\n\t {userSearch.Value.IsVerified}");

            IResult <InstaMediaList> media = await api.GetUserMediaAsync(username, PaginationParameters.MaxPagesToLoad(5));

            List <InstaMedia> mediaList = mediaList = media.Value.ToList();

            for (int i = 0; i < mediaList.Count; i++)
            {
                InstaMedia m = mediaList[i];
                if (m != null && m.Caption != null)
                {
                    string captionText = m.Caption.Text;
                    if (captionText != null)
                    {
                        if (m.MediaType == InstaMediaType.Image)
                        {
                            for (int X = 0; X < m.Images.Count; X++)
                            {
                                if (m.Images[X] != null && m.Images[X].URI != null)
                                {
                                    Console.WriteLine($"\n\t{captionText}");
                                    string uri = m.Images[X].URI;

                                    Console.Write($"{uri}\n\t");
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #30
0
        public async Task <IResult <InstaMediaList> > GetMediaByUser(string User)
        {
            try
            {
                var Credentials = new UserSessionData();
                Credentials.UserName = "******";
                Credentials.Password = "******";

                var Api = InstagramClient
                          .SetUser(Credentials)
                          .Build();

                var Result = await Api.LoginAsync();

                Console.WriteLine(Result.Succeeded);

                var Parameters = PaginationParameters.MaxPagesToLoad(10);
                IResult <InstaMediaList> Media = await Api.GetUserMediaAsync(User, Parameters);
                await UploadMedia(Media, User);

                return(Media);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(null);
        }