Ejemplo n.º 1
0
        private async Task <IActionResult> MakeRequest(OAuthResponse oauthResponse)
        {
            int statusCode = 200;
            var tags       = new InstaSharp.Endpoints.Tags(_config, oauthResponse);

            tags.EnableEnforceSignedHeader(LocalhostIp);

            var likes = new InstaSharp.Endpoints.Likes(_config, oauthResponse);

            likes.EnableEnforceSignedHeader(LocalhostIp);


            var photos = await tags.Recent("foundyourbook");

            foreach (var photo in photos.Data)
            {
                if (!(photo.UserHasLiked ?? false))
                {
                    Thread.Sleep(1200);
                    var likeResult = await likes.Post(photo.Id);

                    statusCode = (int)likeResult.Meta.Code;
                    if (statusCode == 429)
                    {
                        break;
                    }
                }
            }

            return(View("index", statusCode));
        }
Ejemplo n.º 2
0
        public static async Task<string> TagsAsync(string query, OAuthResponse oAuthResponse)
        {
            var tags = new InstaSharp.Endpoints.Tags(InstagramConfig, oAuthResponse);
            var searchResults = await tags.Recent(query);

            return SerializeResults(searchResults.Data);
        }
Ejemplo n.º 3
0
        public static async Task <string> TagsAsync(string query, OAuthResponse oAuthResponse)
        {
            var tags          = new InstaSharp.Endpoints.Tags(InstagramConfig, oAuthResponse);
            var searchResults = await tags.Recent(query);

            return(SerializeResults(searchResults.Data));
        }
Ejemplo n.º 4
0
        private async Task <MediasResponse> GetTagsMediaAsync(string lastId)
        {
            var random       = new Random();
            var tagsEndpoint = new InstaSharp.Endpoints.Tags(ApiConfig);

            var tag    = TagsToProcess.ToArray()[random.Next(0, TagsToProcess.Count() - 1)];
            var result = await tagsEndpoint.Recent(tag.Tag.NormalizeIt(), lastId, null, 50);

            random       = null;
            tagsEndpoint = null;
            return(result);
        }
Ejemplo n.º 5
0
        public async Task ReadMedia(InstaConfig configData, int keywordIndex)
        {
            var clientId = configData.id;
            var clientSecret = configData.secret;

            InstagramConfig config = new InstagramConfig(clientId, clientSecret);

            OAuthResponse oauthResponse = new OAuthResponse();

            oauthResponse.Access_Token = configData.token;
            oauthResponse.User = new User() { FullName = "Dave Brown", Username = "******" };

            var tagEndpoint = new InstaSharp.Endpoints.Tags(config, oauthResponse);
            try
            {
                List<String> keywords = new List<string>() { "photoshoot", "fashion", "model", "modeling", "modelling", "models" };

                string currentKeyword = keywords[keywordIndex];

                SendToLoggerAndConsole("The keyword we're going to work through: " + currentKeyword + " For token: " + configData.token.ToString());
                MediasResponse recentMedia;
                try
                {
                    recentMedia = await tagEndpoint.Recent(currentKeyword);
                }
                catch (Exception ex)
                {
                    SendToLoggerAndConsole("There was a problem getting recent media.");
                    log.Error("Here's the exception", ex);
                    SendToLoggerAndConsole("Bailing out of this key: " + configData.token.ToString());
                    return;
                }

                var likesEndpoint = new InstaSharp.Endpoints.Likes(config, oauthResponse);
                var commentsEndpoint = new InstaSharp.Endpoints.Comments(config, oauthResponse);

                SendToLoggerAndConsole("We have " + recentMedia.Data.Count.ToString() + " images to work through");
                SendToLoggerAndConsole("Here's the amount of likes we have remaining: " + recentMedia.RateLimitRemaining.ToString() + " For token: " + configData.token.ToString());
                bool rateLimitExceeded = recentMedia.RateLimitRemaining < 4971;
                int badResponseCount = 1;
                foreach (var image in recentMedia.Data)
                {
                    if (!image.UserHasLiked.Value)
                    {
                        if (!rateLimitExceeded)
                        {
                            SendToLoggerAndConsole("About to start liking now picture id: " + image.Id);
                            try
                            {

                                var likeResponse = await likesEndpoint.Post(image.Id);
                                rateLimitExceeded = likeResponse.RateLimitRemaining < 4971;
                                SendToLoggerAndConsole("Like response: " + likeResponse.Meta.Code.ToString() + " For token: " + configData.token.ToString());
                                SendToLoggerAndConsole("You have : " + likeResponse.RateLimitRemaining.ToString() + " remaining on token: " + configData.token.ToString());
                                SendToLoggerAndConsole("You are working on keyword: " + currentKeyword);
                                SendToLoggerAndConsole("Currently on Index: " + configData.index.ToString());
                                if (likeResponse.Meta.Code != System.Net.HttpStatusCode.OK)
                                {
                                    SendToLoggerAndConsole("Because the like response was: " + likeResponse.Meta.Code.ToString() + " For token: " + configData.token.ToString());
                                    SendToLoggerAndConsole("We're going to wait: " + (30 * badResponseCount).ToString() + " minutes before we like another shot");
                                    await Task.Delay(new TimeSpan(0, 30 * badResponseCount, 0)).ConfigureAwait(continueOnCapturedContext: false);
                                    badResponseCount++;
                                }
                                else
                                {
                                    badResponseCount = 1;
                                    SendToLoggerAndConsole("Just liked " + image.Id + " For token: " + configData.token.ToString());
                                    await Task.Delay(new TimeSpan(0, 0, new Random(DateTime.Now.Millisecond).Next(200, 300))).ConfigureAwait(continueOnCapturedContext: false);
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            catch
            {

            }
        }
Ejemplo n.º 6
0
        private async Task<MediasResponse> GetTagsMediaAsync(string lastId)
        {
            var random = new Random();
            var tagsEndpoint = new InstaSharp.Endpoints.Tags(ApiConfig);

            var tag = TagsToProcess.ToArray()[random.Next(0, TagsToProcess.Count() - 1)];
            var result = await tagsEndpoint.Recent(tag.Tag.NormalizeIt(), lastId, null, 50);

            random = null;
            tagsEndpoint = null;
            return result;
        }