Ejemplo n.º 1
0
        /// <summary>
        /// Create a comment on a media. Please email apidevelopers[at]instagram.com for access.
        /// </summary>
        /// <param name="mediaid"></param>
        /// <param name="text"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public bool CommentAdd(string mediaid, string text, string accessToken)
        {
            string url = oAuthIns.Configuration.ApiBaseUrl + "media/" + mediaid + "/comments?access_token=" + accessToken;
            NameValueCollection post = new NameValueCollection
            {
                { "text", text },
                { "access_token", accessToken }
            };
            string json = oAuthIns.RequestPostToUrl(url, post, oAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(true);
            }

            InstagramResponse <Comment> res = Base.DeserializeObject <InstagramResponse <Comment> >(json);

            return(res.meta.code == "200");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// List the users who have requested the authenticated user's permission to follow.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public InstagramResponse <User[]> CurrentUserRequestedBy(string accessToken)
        {
            string url = objoAuthIns.Configuration.ApiBaseUrl + "users/self/requested-by?access_token=" + accessToken;



            string json = objoAuthIns.RequestGetToUrl(url, objoAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <User[]> res = Base.DeserializeObject <InstagramResponse <User[]> >(json);



            return(res);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a comment on a media. Please email apidevelopers[at]instagram.com for access.
        /// </summary>
        /// <param name="mediaid"></param>
        /// <param name="text"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public string CommentAdd(string mediaid, string text, string accessToken)
        {
            string url = "https://api.instagram.com/v1/media/" + mediaid + "/comments?access_token=" + accessToken;
            NameValueCollection post = new NameValueCollection
            {
                { "text", text },
                { "access_token", accessToken }
            };
            string json = oAuthIns.RequestPostToUrl(url, post, null);

            if (string.IsNullOrEmpty(json))
            {
                return("");
            }

            InstagramResponse <Comment> res = Base.DeserializeObject <InstagramResponse <Comment> >(json);

            return(json);
        }
Ejemplo n.º 4
0
        public bool CommentDelete(string mediaid, string commentid, string accessToken)
        {
            string url  = Configuration.ApiBaseUrl + "media/" + mediaid + "/comments/" + commentid + "?access_token=" + accessToken;
            string json = RequestDeleteToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(false);
            }

            InstagramResponse <Comment> res = DeserializeObject <InstagramResponse <Comment> >(json);

            if (_cache != null)
            {
                _cache.Remove("media/" + mediaid);
            }

            return(res.meta.code == "200");
        }
Ejemplo n.º 5
0
        public InstagramResponse <Tag[]> TagSearch(string query, string accessToken)
        {
            if (query.Contains("#"))
            {
                query = query.Replace("#", "");
            }

            string url = Configuration.ApiBaseUrl + "tags/search?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "tags/search?client_id=" + Configuration.ClientId;
            }

            if (!string.IsNullOrEmpty(query))
            {
                url = url + "&q=" + query;
            }

            if (_cache != null)
            {
                if (_cache.Exists(url))
                {
                    return(_cache.Get <InstagramResponse <Tag[]> >(url));
                }
            }

            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <Tag[]> res = DeserializeObject <InstagramResponse <Tag[]> >(json);

            if (_cache != null)
            {
                _cache.Add(url, res, 300);
            }

            return(res);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the list of users authenticated user follows.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="max_user_id"></param>
        /// <returns></returns>
        public InstagramResponse <User[]> CurrentUserFollows(string accessToken, string max_user_id)
        {
            string url = objoAuthIns.Configuration.ApiBaseUrl + "users/self/follows?access_token=" + accessToken;

            //  if (!string.IsNullOrEmpty(max_user_id)) url = url + "&cursor=" + max_user_id;

            string json = objoAuthIns.RequestGetToUrl(url, objoAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <User[]> res = Base.DeserializeObject <InstagramResponse <User[]> >(json);



            return(res);
        }
Ejemplo n.º 7
0
        public InstagramResponse <InstagramMedia[]> UserRecentMedia(string userid, string min_id, string max_id, string count, string min_timestamp, string max_timestamp, string accessToken)
        {
            string url = Configuration.ApiBaseUrl + "users/" + userid + "/media/recent?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "users/" + userid + "/media/recent?client_id=" + Configuration.ClientId;
            }

            if (!string.IsNullOrEmpty(min_id))
            {
                url = url + "&min_id=" + min_id;
            }
            if (!string.IsNullOrEmpty(max_id))
            {
                url = url + "&max_id=" + max_id;
            }
            if (!string.IsNullOrEmpty(count))
            {
                url = url + "&count=" + count;
            }
            if (!string.IsNullOrEmpty(min_timestamp))
            {
                url = url + "&min_timestamp=" + min_timestamp;
            }
            if (!string.IsNullOrEmpty(max_timestamp))
            {
                url = url + "&max_timestamp=" + max_timestamp;
            }

            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <InstagramMedia[]> res = DeserializeObject <InstagramResponse <InstagramMedia[]> >(json);


            return(res);
        }
Ejemplo n.º 8
0
        public Location LocationDetails(string locationid, string accessToken)
        {
            string url = Configuration.ApiBaseUrl + "locations/" + locationid + "?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "locations/" + locationid + "?client_id=" + Configuration.ClientId;
            }

            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <Location> res = DeserializeObject <InstagramResponse <Location> >(json);

            return(res.data);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get a list of what media is most popular at the moment.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public InstagramResponse <InstagramMedia[]> MediaPopular(string accessToken)
        {
            string url = oAuthIns.Configuration.ApiBaseUrl + "media/popular?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = oAuthIns.Configuration.ApiBaseUrl + "media/popular?client_id=" + oAuthIns.Configuration.ClientId;
            }

            string json = oAuthIns.RequestGetToUrl(url, oAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <InstagramMedia[]> res = Base.DeserializeObject <InstagramResponse <InstagramMedia[]> >(json);

            return(res);
        }
Ejemplo n.º 10
0
        public InstagramResponse <Comment[]> Comments(string mediaid, string accessToken)
        {
            string url = Configuration.ApiBaseUrl + "media/" + mediaid + "/comments?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "media/" + mediaid + "/comments?client_id=" + Configuration.ClientId;
            }

            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <Comment[]> res = DeserializeObject <InstagramResponse <Comment[]> >(json);

            return(res);
        }
Ejemplo n.º 11
0
        public InstagramResponse <User[]> UsersSearch(string query, string count, string accessToken)
        {
            string url = Configuration.ApiBaseUrl + "users/search?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "users/search?client_id=" + Configuration.ClientId;
            }

            if (_cache != null)
            {
                if (_cache.Exists(url))
                {
                    return(_cache.Get <InstagramResponse <User[]> >(url));
                }
            }

            if (!string.IsNullOrEmpty(query))
            {
                url = url + "&q=" + query;
            }
            if (!string.IsNullOrEmpty(count))
            {
                url = url + "&count=" + count;
            }
            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <User[]> res = DeserializeObject <InstagramResponse <User[]> >(json);

            if (_cache != null)
            {
                _cache.Add(url, res, 300);
            }

            return(res);
        }
Ejemplo n.º 12
0
        public InstagramResponse <InstagramMedia> MediaDetails(string mediaid, string accessToken, bool shortcode = false)
        {
            string mediaPrefix = "media/";

            if (shortcode)
            {
                mediaPrefix += "shortcode/";
            }

            string url = Configuration.ApiBaseUrl + mediaPrefix + mediaid + "?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + mediaPrefix + mediaid + "?client_id=" + Configuration.ClientId;
            }

            if (_cache != null)
            {
                if (_cache.Exists(mediaPrefix + mediaid))
                {
                    return(_cache.Get <InstagramResponse <InstagramMedia> >(mediaPrefix + mediaid));
                }
            }

            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <InstagramMedia> res = DeserializeObject <InstagramResponse <InstagramMedia> >(json);

            if (_cache != null)
            {
                _cache.Add(mediaPrefix + mediaid, res, 60);
            }

            return(res);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get the list of users this user is followed by.
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="accessToken"></param>
        /// <param name="max_user_id"></param>
        /// <returns></returns>
        public InstagramResponse <User[]> UserFollowedBy(string userid, string accessToken, string max_user_id)
        {
            string url = objoAuthIns.Configuration.ApiBaseUrl + "users/" + userid + "/followed-by?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = objoAuthIns.Configuration.ApiBaseUrl + "users/" + userid + "/followed-by?client_id=" + objoAuthIns.Configuration.ClientId;
            }


            string json = objoAuthIns.RequestGetToUrl(url, objoAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <User[]> res = Base.DeserializeObject <InstagramResponse <User[]> >(json);


            return(res);
        }
Ejemplo n.º 14
0
        public IHttpActionResult LoginInstagram(InstagramResponse profile)
        {
            var user = UsersHelper.GetUserASP(profile.UserData.Id);

            if (user != null)
            {
                return(Ok(true)); // TODO: Pending update the user with new instagram data
            }

            var firstName = string.Empty;
            var lastName  = string.Empty;
            var fullName  = profile.UserData.FullName;
            var posSpace  = fullName.IndexOf(' ');

            if (posSpace == -1)
            {
                firstName = fullName;
                lastName  = fullName;
            }
            else
            {
                firstName = fullName.Substring(0, posSpace);
                lastName  = fullName.Substring(posSpace + 1);
            }

            var userRequest = new UserRequest
            {
                EMail     = profile.UserData.Id,
                FirstName = firstName,
                ImagePath = profile.UserData.ProfilePicture,
                LastName  = lastName,
                Password  = profile.UserData.Id,
            };

            var answer = UsersHelper.CreateUserASP(userRequest);

            return(Ok(answer));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Get the list of users this user follows.
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="accessToken"></param>
        /// <param name="max_user_id"></param>
        /// <returns></returns>
        public InstagramResponse <User[]> UserFollows(string userid, string accessToken, string max_user_id)
        {
            string url = objoAuthIns.Configuration.ApiBaseUrl + "users/" + userid + "/follows?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = objoAuthIns.Configuration.ApiBaseUrl + "users/" + userid + "/follows?client_id=" + objoAuthIns.Configuration.ClientId;
            }

            string json = objoAuthIns.RequestGetToUrl(url, objoAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <User[]> res = Base.DeserializeObject <InstagramResponse <User[]> >(json);

            //https://api.instagram.com/v1/users/530914/follows?access_token=530914.0c0b99a.56e7a173b9af43eba8a60759904f6fc4&cursor=32754039"
            //if (_cache != null)
            //    _cache.Add(userid + "/follows", res);

            return(res);
        }
Ejemplo n.º 16
0
        public InstagramMedia[] LocationMedia(string locationid, string min_id, string max_id, string min_timestamp, string max_timestamp, string accessToken)
        {
            string url = Configuration.ApiBaseUrl + "locations/" + locationid + "/media/recent?access_token=" + accessToken;

            if (string.IsNullOrEmpty(accessToken))
            {
                url = Configuration.ApiBaseUrl + "locations/" + locationid + "/media/recent?client_id=" + Configuration.ClientId;
            }

            if (!string.IsNullOrEmpty(min_id))
            {
                url = url + "&min_id=" + min_id;
            }
            if (!string.IsNullOrEmpty(max_id))
            {
                url = url + "&max_id=" + max_id;
            }
            if (!string.IsNullOrEmpty(min_timestamp))
            {
                url = url + "&min_timestamp=" + min_timestamp;
            }
            if (!string.IsNullOrEmpty(max_timestamp))
            {
                url = url + "&max_timestamp=" + max_timestamp;
            }
            string json = RequestGetToUrl(url, Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(new InstagramMedia[0]);
            }

            InstagramResponse <InstagramMedia[]> res = DeserializeObject <InstagramResponse <InstagramMedia[]> >(json);

            return(res.data);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// See the authenticated user's list of media they've liked.
        /// </summary>
        /// <param name="max_like_id">  Return media liked before this id.</param>
        /// <param name="count">Count of media to return.</param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public InstagramResponse <InstagramMedia[]> CurrentUserLikedMedia(string max_like_id, string count, string accessToken)
        {
            string url = objoAuthIns.Configuration.ApiBaseUrl + "users/self/media/liked?access_token=" + accessToken;

            if (!string.IsNullOrEmpty(max_like_id))
            {
                url = url + "&max_like_id=" + max_like_id;
            }
            if (!string.IsNullOrEmpty(count))
            {
                url = url + "&count=" + count;
            }

            string json = objoAuthIns.RequestGetToUrl(url, objoAuthIns.Configuration.Proxy);

            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }

            InstagramResponse <InstagramMedia[]> res = Base.DeserializeObject <InstagramResponse <InstagramMedia[]> >(json);

            return(res);
        }
Ejemplo n.º 18
0
        public async Task <TokenResponse> LoginInstagram(string urlBase, string servicePrefix, string controller, InstagramResponse profile)
        {
            try
            {
                var request = JsonConvert.SerializeObject(profile);
                var content = new StringContent(request, Encoding.UTF8, "application/json");
                var client  = new HttpClient();
                //client.BaseAddress = new Uri(urlBase);
                var url      = $"{urlBase}{servicePrefix}{controller}";
                var response = await client.PostAsync(url, content);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                var tokenResponse = await GetToken(urlBase, profile.UserData.Id, profile.UserData.Id);

                return(tokenResponse);
            }
            catch
            {
                return(null);
            }
        }
        public static void GetInstagramSelfFeeds(string instagramId, string accessToken, Helper.AppSettings _appSettings)
        {
            MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment", _appSettings);
            MongoRepository instagramFeedRepo    = new MongoRepository("InstagramFeed", _appSettings);

            try
            {
                Users userInstagram = new Users();
                Media _Media        = new Media();
                InstagramResponse <Comment[]> usercmts   = new InstagramResponse <Comment[]>();
                CommentController             objComment = new CommentController();
                LikesController objLikes = new LikesController();
                string          feeds    = _Media.UserResentFeeds(instagramId, accessToken);
                if (feeds != null)
                {
                    JObject feed_data = JObject.Parse(feeds);

                    foreach (var item in feed_data["data"])
                    {
                        try
                        {
                            Domain.Socioboard.Models.Mongo.InstagramFeed objInstagramFeed = new Domain.Socioboard.Models.Mongo.InstagramFeed();
                            try
                            {
                                objInstagramFeed.FeedDate = Convert.ToDouble(item["created_time"].ToString());
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = item["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Type = item["type"].ToString();
                                if (objInstagramFeed.Type == "video")
                                {
                                    objInstagramFeed.VideoUrl = item["videos"]["standard_resolution"]["url"].ToString();
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = item["images"]["standard_resolution"]["url"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = instagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                string str = item["user_has_liked"].ToString();
                                if (str.ToLower() == "false")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else
                                {
                                    objInstagramFeed.IsLike = 1;
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = item["user"]["username"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = item["caption"]["text"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = item["user"]["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = item["link"].ToString();
                            }
                            catch { }

                            var ret  = instagramFeedRepo.Find <Domain.Socioboard.Models.Mongo.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                FilterDefinition <BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders <BsonDocument> .Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);

                                instagramFeedRepo.Update <Domain.Socioboard.Models.Mongo.InstagramFeed>(update, filter);
                            }
                            List <Domain.Socioboard.Models.Mongo.InstagramComment> lstInstagramComment = new List <Domain.Socioboard.Models.Mongo.InstagramComment>();
                            usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    Domain.Socioboard.Models.Mongo.InstagramComment objInstagramComment = new Domain.Socioboard.Models.Mongo.InstagramComment();
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = Convert.ToDouble(usercmts.data[cmt].created_time.ToString());
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }

                                    try
                                    {
                                        objInstagramComment.FeedId = objInstagramFeed.FeedId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = instagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            instagarmCommentRepo.AddList(lstInstagramComment);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 20
0
        public void GetInstagramSelfFeeds(string instagramId, string accessToken)
        {
            MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment");
            MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed");
            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                GlobusInstagramLib.Instagram.Core.MediaMethods.Media _Media = new GlobusInstagramLib.Instagram.Core.MediaMethods.Media();
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                string feeds = _Media.UserResentFeeds(instagramId, accessToken);
                if (feeds != null)
                {
                    JObject feed_data = JObject.Parse(feeds);

                    foreach (var item in feed_data["data"])
                    {
                        try
                        {
                            Domain.Socioboard.MongoDomain.InstagramFeed objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                            try
                            {
                                objInstagramFeed.FeedDate = item["created_time"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = item["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Type = item["type"].ToString();
                                if (objInstagramFeed.Type == "video")
                                {
                                    objInstagramFeed.VideoUrl = item["videos"]["standard_resolution"]["url"].ToString();
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = item["images"]["standard_resolution"]["url"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = instagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = Int32.Parse(item["likes"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = Int32.Parse(item["comments"]["count"].ToString());
                            }
                            catch { }
                            try
                            {
                                string str = item["user_has_liked"].ToString();
                                if (str.ToLower() == "false")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = item["user"]["username"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = item["caption"]["text"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = item["user"]["id"].ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = item["link"].ToString();
                            }
                            catch { }

                            var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async () =>
                            {
                                return await ret;
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
                                instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
                            }
                            List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
                            usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }

                                    try
                                    {
                                        objInstagramComment.FeedId = objInstagramFeed.FeedId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = instagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {

                                }
                            }
                            instagarmCommentRepo.AddList(lstInstagramComment);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 21
0
        public void GetInstagramFeeds(Domain.Socioboard.Domain.InstagramAccount objInsAccount)
        {
            MongoRepository instagarmCommentRepo = new MongoRepository("InstagramComment");
            MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed");
            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                InstagramResponse<InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "30", objInsAccount.AccessToken);
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();

                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            objInstagramFeed = new Domain.Socioboard.MongoDomain.InstagramFeed();
                            //objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                // objInstagramFeed.Id = ObjectId.GenerateNewId();
                                objInstagramFeed.strId = ObjectId.GenerateNewId().ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Type = userinf2.data[j].type.ToString();
                                if (objInstagramFeed.Type == "video")
                                {
                                    objInstagramFeed.VideoUrl = userinf2.data[j].videos.standard_resolution.url.ToString();
                                }
                            }
                            catch { } 
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch { }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();
                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = userinf2.data[j].caption.text;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = userinf2.data[j].link;
                            }
                            catch { }
                            //try
                            //{
                            //    objInstagramFeed.UserId = objInsAccount.UserId.;
                            //}
                            //catch { }

                            var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async () =>
                            {
                                return await ret;
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
                                instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
                            }

                            //if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            //{
                            //    objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            //}
                            List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {

                                    Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();

                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }
                                    //try
                                    //{
                                    //    objInstagramComment.EntryDate = DateTime.UtcNow.ToString();
                                    //}
                                    //catch { }
                                    try
                                    {
                                        objInstagramComment.FeedId = userinf2.data[j].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.Id = ObjectId.GenerateNewId();
                                        objInstagramComment.strId = ObjectId.GenerateNewId().ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        // objInstagramComment.UserId = objInsAccount.UserId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                }
                            }
                            instagarmCommentRepo.AddList(lstInstagramComment);

                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Ejemplo n.º 22
0
        public static int updateInstagramFeeds(Domain.Socioboard.Models.Instagramaccounts insAcc)
        {
            apiHitsCount = 0;
            DatabaseRepository dbr = new DatabaseRepository();

            Domain.Socioboard.Models.Groupprofiles _grpProfile = dbr.Single <Domain.Socioboard.Models.Groupprofiles>(t => t.profileId.Contains(insAcc.InstagramId));
            if (insAcc.lastUpdate.AddHours(1) <= DateTime.UtcNow)
            {
                if (insAcc.IsActive)
                {
                    //  Domain.Socioboard.Models.Instagramaccounts Instagramaccounts = new Domain.Socioboard.Models.Instagramaccounts();
                    Domain.Socioboard.Models.Instagramaccounts objInstagramAccount;
                    UserController   objusercontroller = new UserController();
                    ConfigurationIns configi           = new ConfigurationIns("https://api.instagram.com/oauth/authorize/", "d89b5cfa3796458ebbb2520d70eeb498", "e4663d0a287243f88ac619b5692119c8", "https://www.socioboard.com/InstagramManager/Instagram", "https://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
                    oAuthInstagram   _api = new oAuthInstagram();
                    _api = oAuthInstagram.GetInstance(configi);
                    InstagramResponse <User> objuser = objusercontroller.GetUserDetails(insAcc.InstagramId, insAcc.AccessToken);

                    //  objInstagramAccount = new Domain.Socioboard.Models.Instagramaccounts();


                    if (objuser != null)
                    {
                        try
                        {
                            insAcc.ProfileUrl      = objuser.data.profile_picture;
                            _grpProfile.profilePic = objuser.data.profile_picture;
                        }
                        catch (Exception ex)
                        {
                            insAcc.ProfileUrl      = insAcc.ProfileUrl;
                            _grpProfile.profilePic = insAcc.ProfileUrl;
                        }
                        try
                        {
                            insAcc.TotalImages = objuser.data.counts.media;
                        }
                        catch (Exception ex)
                        {
                            insAcc.TotalImages = insAcc.TotalImages;
                        }
                        try
                        {
                            insAcc.FollowedBy = objuser.data.counts.followed_by;
                        }
                        catch (Exception ex)
                        {
                            insAcc.FollowedBy = insAcc.FollowedBy;
                        }
                        try
                        {
                            insAcc.Followers = objuser.data.counts.follows;
                        }
                        catch (Exception ex)
                        {
                            insAcc.Followers = insAcc.Followers;
                        }
                        try
                        {
                            insAcc.bio = objuser.data.bio;
                        }
                        catch (Exception ex)
                        {
                            insAcc.bio = insAcc.bio;
                        }
                        dbr.Update <Domain.Socioboard.Models.Groupprofiles>(_grpProfile);
                        dbr.Update <Domain.Socioboard.Models.Instagramaccounts>(insAcc);
                    }
                    while (apiHitsCount < MaxapiHitsCount)
                    {
                        try
                        {
                            GetInstagramSelfFeeds(insAcc.InstagramId, insAcc.AccessToken);
                        }
                        catch { }
                        try
                        {
                            GetInstagramUserDetails(insAcc.InstagramId, insAcc.AccessToken, insAcc);
                        }
                        catch { }
                        try
                        {
                            GetInstagramPostLikes(insAcc.InstagramId, insAcc.AccessToken);
                        }
                        catch { }
                        try
                        {
                            GetInstagramPostComments(insAcc.InstagramId, insAcc.AccessToken);
                        }
                        catch { }
                        try
                        {
                            GetInstagramFollowing(insAcc.InstagramId, insAcc.AccessToken, 1);
                        }
                        catch { }
                        try
                        {
                            GetInstagramFollower(insAcc.InstagramId, insAcc.AccessToken, 1);
                        }
                        catch { }
                    }
                    insAcc.lastUpdate = DateTime.UtcNow;
                    dbr.Update <Domain.Socioboard.Models.Instagramaccounts>(insAcc);
                }
            }
            else
            {
                apiHitsCount = 0;
            }

            return(0);
        }
Ejemplo n.º 23
0
        public void getIntagramImages(object instaId)
        {
            Guid instaid = (Guid)instaId;

            InstagramAccountRepository objIns = new InstagramAccountRepository();
            InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>();
            InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
            MediaController objMedia = new MediaController();
            CommentController objComment = new CommentController();
            LikesController objLikes = new LikesController();
            InstagramFeedRepository objInsFeedRepo = new InstagramFeedRepository();
            InstagramFeed objFeed = new InstagramFeed();
            InstagramComment objinsComment = new InstagramComment();
            InstagramCommentRepository objInsRepo = new InstagramCommentRepository();
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"].ToString(), ConfigurationManager.AppSettings["InstagramClientSec"].ToString(), ConfigurationManager.AppSettings["InstagramCallBackURL"].ToString(), "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = oAuthInstagram.GetInstance(configi);
            ArrayList aslt = objIns.getAllInstagramAccountsOfUser(instaid);
            string html = string.Empty;
            int i = 0;
            // string[] allhtmls = new string[aslt.Count];
            string[] allhtmls = new string[0];
            int countofimages = 0;
            foreach (InstagramAccount item in aslt)
            {

                try
                {
                    GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                    try
                    {
                        userinf2 = userInstagram.UserRecentMedia(item.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, item.AccessToken);

                    }
                    catch { }


                }
                catch { }



                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, item.AccessToken);
                            bool liked = false;
                            try
                            {
                                liked = objLikes.LikeToggle(userinf2.data[j].id, item.InstagramId, item.AccessToken);
                            }
                            catch
                            {
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                objinsComment.Comment = usercmts.data[cmt].text;
                                objinsComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                objinsComment.CommentId = usercmts.data[cmt].id;
                                objinsComment.EntryDate = DateTime.Now.ToString();
                                objinsComment.FeedId = userinf2.data[j].id;
                                objinsComment.Id = Guid.NewGuid();
                                objinsComment.InstagramId = item.InstagramId;
                                objinsComment.UserId = item.UserId;
                                objinsComment.FromName = usercmts.data[cmt].from.full_name;
                                objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, item.UserId))
                                    objInsRepo.addInstagramComment(objinsComment);
                            }
                            objFeed.EntryDate = DateTime.Now;
                            objFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            objFeed.FeedId = userinf2.data[j].id;
                            objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            objFeed.InstagramId = item.InstagramId;
                            objFeed.LikeCount = userinf2.data[j].likes.count;
                            objFeed.UserId = item.UserId;
                            if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, item.UserId))
                                objInsFeedRepo.addInstagramFeed(objFeed);


                        }
                        catch
                        {
                        }
                        i++;

                    }
                }
                i++;
           //     allhtmls[countofimages] = html;
                html = string.Empty;
                countofimages++;
                break;
            }
            string totalhtml = string.Empty;
            try
            {
                for (int k = 0; k < countofimages; k++)
                {
                    totalhtml = totalhtml + allhtmls[k];
                }
            }
            catch
            {
            }
          
        }
        public string GetIntagramImages(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            {
                InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>();
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
                MediaController objMedia = new MediaController();
                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed = new Domain.Myfashion.Domain.InstagramFeed();
                string html = string.Empty;
                int i = 0;
                string[] allhtmls = new string[0];
                int countofimages = 0;
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                try
                {
                    userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, objInsAccount.AccessToken);

                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                //liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate = DateTime.Now;
                                    objInstagramComment.FeedId = userinf2.data[j].id;
                                    objInstagramComment.Id = Guid.NewGuid();
                                    objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    objInstagramComment.UserId = objInsAccount.UserId;
                                    objInstagramComment.FromName = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();

                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                try
                {

                    userinf2 = userInstagram.CurrentUserFeed(string.Empty, string.Empty, "20", objInsAccount.AccessToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                // liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate = DateTime.Now;
                                    objInstagramComment.FeedId = userinf2.data[j].id;
                                    objInstagramComment.Id = Guid.NewGuid();
                                    objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    objInstagramComment.UserId = objInsAccount.UserId;
                                    objInstagramComment.FromName = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate = DateTime.Now;
                            objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            objInstagramFeed.FeedId = userinf2.data[j].id;
                            objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            string str = userinf2.data[j].user_has_liked.ToString();
                            if (str == "False")
                            {
                                objInstagramFeed.IsLike = 0;
                            }
                            else { objInstagramFeed.IsLike = 1; }
                            objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username + "-" + userinf2.data[j].caption.from.full_name;

                            objInstagramFeed.UserId = objInsAccount.UserId;
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                i++;

                string totalhtml = string.Empty;
                try
                {
                    for (int k = 0; k < countofimages; k++)
                    {
                        totalhtml = totalhtml + allhtmls[k];
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                // Session["AllHtmls"] = allhtmls;
                return totalhtml;
            }
        }
Ejemplo n.º 25
0
        public string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string         ret      = string.Empty;
            oAuthInstagram objInsta = new oAuthInstagram();

            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();

            access = _api.AuthGetAccessToken(code);
            #region InstagramAccount
            UserController objusercontroller = new UserController();
            InstagramResponse <GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);
            objInstagramAccount             = new Domain.Myfashion.Domain.InstagramAccount();
            objInstagramAccount.AccessToken = access.access_token;
            objInstagramAccount.InstagramId = access.user.id;
            try
            {
                objInstagramAccount.ProfileUrl = access.user.profile_picture;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.InsUserName = access.user.username;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.TotalImages = objuser.data.counts.media;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.Followers = objuser.data.counts.follows;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            objInstagramAccount.UserId = Guid.Parse(UserId);
            #endregion


            if (!objInstagramAccountRepository.checkInstagramUserExists(objInstagramAccount.InstagramId, Guid.Parse(UserId)))
            {
                objInstagramAccountRepository.addInstagramUser(objInstagramAccount);
                #region Add TeamMemberProfile
                Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
                objTeamMemberProfile.Id               = Guid.NewGuid();
                objTeamMemberProfile.TeamId           = objTeam.Id;
                objTeamMemberProfile.Status           = 1;
                objTeamMemberProfile.ProfileType      = "instagram";
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                objTeamMemberProfile.ProfileId        = objInstagramAccount.InstagramId;

                //Modified [13-02-15]
                objTeamMemberProfile.ProfilePicUrl = objInstagramAccount.ProfileUrl;
                objTeamMemberProfile.ProfileName   = objInstagramAccount.InsUserName;

                objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                #endregion
                #region SocialProfile
                Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                objSocialProfile.Id            = Guid.NewGuid();
                objSocialProfile.ProfileType   = "instagram";
                objSocialProfile.ProfileId     = objInstagramAccount.InstagramId;
                objSocialProfile.UserId        = Guid.Parse(UserId);
                objSocialProfile.ProfileDate   = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                #endregion
                #region Add SocialProfile
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }

                #endregion
                ret = "Account Added Successfully";
            }
            else
            {
                ret = "Account already Exist !";
            }

            //GetIntagramImages(objInstagramAccount);
            GetInstagramFeeds(objInstagramAccount);
            return(ret);
        }
Ejemplo n.º 26
0
        public string getIntagramImages(InstagramAccount objInsAccount)
        {
            InstagramAccountRepository objIns = new InstagramAccountRepository();
            InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf  = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse <InstagramMedia[]> userinf2 = new InstagramResponse <InstagramMedia[]>();
            InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
            MediaController            objMedia           = new MediaController();
            CommentController          objComment         = new CommentController();
            LikesController            objLikes           = new LikesController();
            InstagramFeedRepository    objInsFeedRepo     = new InstagramFeedRepository();
            InstagramFeed              objFeed            = new InstagramFeed();
            InstagramComment           objinsComment      = new InstagramComment();
            InstagramCommentRepository objInsRepo         = new InstagramCommentRepository();
            //  ArrayList aslt = objIns.getAllInstagramAccountsOfUser(instaid);
            string html = string.Empty;
            int    i    = 0;

            // string[] allhtmls = new string[aslt.Count];
            string[] allhtmls      = new string[0];
            int      countofimages = 0;

            GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
            try
            {
                userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, objInsAccount.AccessToken);
            }
            catch (Exception ex) {
                logger.Error(ex.StackTrace);
            }


            if (userinf2 != null)
            {
                for (int j = 0; j < userinf2.data.Count(); j++)
                {
                    try
                    {
                        usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                        bool liked = false;
                        try
                        {
                            liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        int n = usercmts.data.Count();
                        for (int cmt = usercmts.data.Count() - 1; cmt > usercmts.data.Count() - 3; cmt--)
                        {
                            try
                            {
                                objinsComment.Comment        = usercmts.data[cmt].text;
                                objinsComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                objinsComment.CommentId      = usercmts.data[cmt].id;
                                objinsComment.EntryDate      = DateTime.Now.ToString();
                                objinsComment.FeedId         = userinf2.data[j].id;
                                objinsComment.Id             = Guid.NewGuid();
                                objinsComment.InstagramId    = objInsAccount.InstagramId;
                                objinsComment.UserId         = objInsAccount.UserId;
                                objinsComment.FromName       = usercmts.data[cmt].from.full_name;
                                objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                {
                                    objInsRepo.addInstagramComment(objinsComment);
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                                Console.WriteLine(ex.StackTrace);
                            }
                        }
                        objFeed.EntryDate    = DateTime.Now;
                        objFeed.FeedDate     = userinf2.data[j].created_time.ToString();
                        objFeed.FeedId       = userinf2.data[j].id;
                        objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                        objFeed.InstagramId  = objInsAccount.InstagramId;
                        objFeed.LikeCount    = userinf2.data[j].likes.count;
                        objFeed.UserId       = objInsAccount.UserId;
                        if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                        {
                            objInsFeedRepo.addInstagramFeed(objFeed);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    i++;
                }
            }
            i++;


            string totalhtml = string.Empty;

            try
            {
                for (int k = 0; k < countofimages; k++)
                {
                    totalhtml = totalhtml + allhtmls[k];
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
            }
            Session["AllHtmls"] = allhtmls;
            return(totalhtml);
        }
Ejemplo n.º 27
0
        public void getIntagramImages(object instaId)
        {
            Guid instaid = (Guid)instaId;

            InstagramAccountRepository objIns = new InstagramAccountRepository();
            InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf  = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse <InstagramMedia[]> userinf2 = new InstagramResponse <InstagramMedia[]>();
            InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
            MediaController            objMedia           = new MediaController();
            CommentController          objComment         = new CommentController();
            LikesController            objLikes           = new LikesController();
            InstagramFeedRepository    objInsFeedRepo     = new InstagramFeedRepository();
            InstagramFeed              objFeed            = new InstagramFeed();
            InstagramComment           objinsComment      = new InstagramComment();
            InstagramCommentRepository objInsRepo         = new InstagramCommentRepository();

            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"].ToString(), ConfigurationManager.AppSettings["InstagramClientSec"].ToString(), ConfigurationManager.AppSettings["InstagramCallBackURL"].ToString(), "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = oAuthInstagram.GetInstance(configi);
            ArrayList      aslt = objIns.getAllInstagramAccountsOfUser(instaid);
            string         html = string.Empty;
            int            i    = 0;

            // string[] allhtmls = new string[aslt.Count];
            string[] allhtmls      = new string[0];
            int      countofimages = 0;

            foreach (InstagramAccount item in aslt)
            {
                try
                {
                    GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                    try
                    {
                        userinf2 = userInstagram.UserRecentMedia(item.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, item.AccessToken);
                    }
                    catch { }
                }
                catch { }



                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, item.AccessToken);
                            bool liked = false;
                            try
                            {
                                liked = objLikes.LikeToggle(userinf2.data[j].id, item.InstagramId, item.AccessToken);
                            }
                            catch
                            {
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                objinsComment.Comment        = usercmts.data[cmt].text;
                                objinsComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                objinsComment.CommentId      = usercmts.data[cmt].id;
                                objinsComment.EntryDate      = DateTime.Now.ToString();
                                objinsComment.FeedId         = userinf2.data[j].id;
                                objinsComment.Id             = Guid.NewGuid();
                                objinsComment.InstagramId    = item.InstagramId;
                                objinsComment.UserId         = item.UserId;
                                objinsComment.FromName       = usercmts.data[cmt].from.full_name;
                                objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, item.UserId))
                                {
                                    objInsRepo.addInstagramComment(objinsComment);
                                }
                            }
                            objFeed.EntryDate    = DateTime.Now;
                            objFeed.FeedDate     = userinf2.data[j].created_time.ToString();
                            objFeed.FeedId       = userinf2.data[j].id;
                            objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            objFeed.InstagramId  = item.InstagramId;
                            objFeed.LikeCount    = userinf2.data[j].likes.count;
                            objFeed.UserId       = item.UserId;
                            if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, item.UserId))
                            {
                                objInsFeedRepo.addInstagramFeed(objFeed);
                            }
                        }
                        catch
                        {
                        }
                        i++;
                    }
                }
                i++;
                //     allhtmls[countofimages] = html;
                html = string.Empty;
                countofimages++;
                break;
            }
            string totalhtml = string.Empty;

            try
            {
                for (int k = 0; k < countofimages; k++)
                {
                    totalhtml = totalhtml + allhtmls[k];
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 28
0
        public string getIntagramImages( InstagramAccount objInsAccount)
        {
            InstagramAccountRepository objIns = new InstagramAccountRepository();
            InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse<GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse<GlobusInstagramLib.App.Core.User[]>();
            InstagramResponse<InstagramMedia[]> userinf2 = new InstagramResponse<InstagramMedia[]>();
            InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
            MediaController objMedia = new MediaController();
            CommentController objComment = new CommentController();
            LikesController objLikes = new LikesController();
            InstagramFeedRepository objInsFeedRepo = new InstagramFeedRepository();
            InstagramFeed objFeed = new InstagramFeed();
            InstagramComment objinsComment = new InstagramComment();
            InstagramCommentRepository objInsRepo = new InstagramCommentRepository();
          //  ArrayList aslt = objIns.getAllInstagramAccountsOfUser(instaid);
            string html = string.Empty;
            int i = 0;
            // string[] allhtmls = new string[aslt.Count];
            string[] allhtmls = new string[0];
            int countofimages = 0;
            GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                    try
                    {
                        userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId,string.Empty,string.Empty,"20",string.Empty,string.Empty,objInsAccount.AccessToken);

                    }
                    catch(Exception ex) {
                        logger.Error(ex.StackTrace);
                    }


                    if (userinf2 != null)
                    {
                        for (int j = 0; j < userinf2.data.Count(); j++)
                        {
                            try
                            {
                                usercmts = objComment.GetComment(userinf2.data[j].id,objInsAccount.AccessToken);
                                bool liked = false;
                                try
                                {
                                    liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                                }
                                catch(Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                }
                                int n = usercmts.data.Count();
                                for (int cmt = usercmts.data.Count() - 1; cmt > usercmts.data.Count() - 3; cmt--)
                                {
                                    try
                                    {
                                        objinsComment.Comment = usercmts.data[cmt].text;
                                        objinsComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                        objinsComment.CommentId = usercmts.data[cmt].id;
                                        objinsComment.EntryDate = DateTime.Now.ToString();
                                        objinsComment.FeedId = userinf2.data[j].id;
                                        objinsComment.Id = Guid.NewGuid();
                                        objinsComment.InstagramId = objInsAccount.InstagramId;
                                        objinsComment.UserId = objInsAccount.UserId;
                                        objinsComment.FromName = usercmts.data[cmt].from.full_name;
                                        objinsComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                        if (!objInsRepo.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                            objInsRepo.addInstagramComment(objinsComment);
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Error(ex.StackTrace);
                                        Console.WriteLine(ex.StackTrace);
                                    }
                                }
                                objFeed.EntryDate = DateTime.Now;
                                objFeed.FeedDate = userinf2.data[j].created_time.ToString();
                                objFeed.FeedId = userinf2.data[j].id;
                                objFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                                objFeed.InstagramId = objInsAccount.InstagramId;
                                objFeed.LikeCount = userinf2.data[j].likes.count;
                                objFeed.UserId = objInsAccount.UserId;
                                if (!objInsFeedRepo.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                                    objInsFeedRepo.addInstagramFeed(objFeed);


                            }
                            catch(Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            i++;

                        }
                    }
                    i++;
                
            
            string totalhtml = string.Empty;
            try
            {
                for (int k = 0; k < countofimages; k++)
                {
                    totalhtml = totalhtml + allhtmls[k];
                }
            }
            catch(Exception ex)
            {
                logger.Error(ex.StackTrace);

            }
            Session["AllHtmls"] = allhtmls;
            return totalhtml;

          
        }
Ejemplo n.º 29
0
        public void GetInstagramFeeds(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            int I = 0;

            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                InstagramResponse <InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "20", objInsAccount.AccessToken);
                InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed    = new Domain.Myfashion.Domain.InstagramFeed();
                CommentController objComment = new CommentController();
                LikesController   objLikes   = new LikesController();
                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch { }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();
                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else
                                {
                                    objInstagramFeed.IsLike = 1;
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = userinf2.data[j].caption.text;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = userinf2.data[j].link;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch { }
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                I++;
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                                logger.Error("GetInstagramFeedsCount>>>" + I);
                            }

                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.EntryDate = DateTime.Now;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FeedId = userinf2.data[j].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.Id = Guid.NewGuid();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.UserId = objInsAccount.UserId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Ejemplo n.º 30
0
        public string GetIntagramImages(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            {
                InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf  = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse <InstagramMedia[]> userinf2 = new InstagramResponse <InstagramMedia[]>();
                InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
                MediaController   objMedia   = new MediaController();
                CommentController objComment = new CommentController();
                LikesController   objLikes   = new LikesController();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed    = new Domain.Myfashion.Domain.InstagramFeed();
                string   html          = string.Empty;
                int      i             = 0;
                string[] allhtmls      = new string[0];
                int      countofimages = 0;
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                try
                {
                    userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, objInsAccount.AccessToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                //liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment        = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId      = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate      = DateTime.Now;
                                    objInstagramComment.FeedId         = userinf2.data[j].id;
                                    objInstagramComment.Id             = Guid.NewGuid();
                                    objInstagramComment.InstagramId    = objInsAccount.InstagramId;
                                    objInstagramComment.UserId         = objInsAccount.UserId;
                                    objInstagramComment.FromName       = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();

                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else
                                {
                                    objInstagramFeed.IsLike = 1;
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                try
                {
                    userinf2 = userInstagram.CurrentUserFeed(string.Empty, string.Empty, "20", objInsAccount.AccessToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                // liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment        = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId      = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate      = DateTime.Now;
                                    objInstagramComment.FeedId         = userinf2.data[j].id;
                                    objInstagramComment.Id             = Guid.NewGuid();
                                    objInstagramComment.InstagramId    = objInsAccount.InstagramId;
                                    objInstagramComment.UserId         = objInsAccount.UserId;
                                    objInstagramComment.FromName       = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate    = DateTime.Now;
                            objInstagramFeed.FeedDate     = userinf2.data[j].created_time.ToString();
                            objInstagramFeed.FeedId       = userinf2.data[j].id;
                            objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            objInstagramFeed.InstagramId  = objInsAccount.InstagramId;
                            objInstagramFeed.LikeCount    = userinf2.data[j].likes.count;
                            objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            string str = userinf2.data[j].user_has_liked.ToString();
                            if (str == "False")
                            {
                                objInstagramFeed.IsLike = 0;
                            }
                            else
                            {
                                objInstagramFeed.IsLike = 1;
                            }
                            objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username + "-" + userinf2.data[j].caption.from.full_name;

                            objInstagramFeed.UserId = objInsAccount.UserId;
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                i++;

                string totalhtml = string.Empty;
                try
                {
                    for (int k = 0; k < countofimages; k++)
                    {
                        totalhtml = totalhtml + allhtmls[k];
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                // Session["AllHtmls"] = allhtmls;
                return(totalhtml);
            }
        }
        public static string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string code, long userId, long groupId, Model.DatabaseRepository dbr, ILogger _logger, Helper.Cache _redisCache, Helper.AppSettings _appSettings)
        {
            string           ret      = string.Empty;
            oAuthInstagram   objInsta = new oAuthInstagram();
            ConfigurationIns configi  = new ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "https://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram   _api     = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();

            access = _api.AuthGetAccessToken(code);
            UserController objusercontroller = new UserController();

            if (access != null)
            {
                Domain.Socioboard.Models.Instagramaccounts Instagramaccounts = new Domain.Socioboard.Models.Instagramaccounts();
                Domain.Socioboard.Models.Instagramaccounts objInstagramAccount;
                #region InstagramAccount
                InstagramResponse <User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

                objInstagramAccount             = new Domain.Socioboard.Models.Instagramaccounts();
                objInstagramAccount.AccessToken = access.access_token;
                objInstagramAccount.InstagramId = access.user.id;
                try
                {
                    objInstagramAccount.bio = access.user.bio;
                }
                catch {
                    objInstagramAccount.bio = "";
                }
                try
                {
                    objInstagramAccount.ProfileUrl = access.user.profile_picture;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.InsUserName = access.user.username;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.TotalImages = objuser.data.counts.media;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                try
                {
                    objInstagramAccount.Followers = objuser.data.counts.follows;
                }
                catch (Exception ex)
                {
                    _logger.LogError("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
                }
                objInstagramAccount.UserId     = userId;
                objInstagramAccount.IsActive   = true;
                objInstagramAccount.lastUpdate = DateTime.UtcNow;
                if (objInstagramAccount.InstagramId != null)
                {
                    Instagramaccounts = Api.Socioboard.Repositories.InstagramRepository.getInstagramAccount(objInstagramAccount.InstagramId, _redisCache, dbr);
                    if (Instagramaccounts != null && Instagramaccounts.IsActive == true)
                    {
                        return("This Account is added by some body else.");
                    }
                }
                else
                {
                    return("Issue while fetching instagram userId");
                }

                if (Instagramaccounts == null)
                {
                    int isSaved = dbr.Add <Domain.Socioboard.Models.Instagramaccounts>(objInstagramAccount);
                    if (isSaved == 1)
                    {
                        List <Domain.Socioboard.Models.Instagramaccounts> lstinsAcc = dbr.Find <Domain.Socioboard.Models.Instagramaccounts>(t => t.InstagramId.Equals(objInstagramAccount.InstagramId)).ToList();
                        if (lstinsAcc != null && lstinsAcc.Count() > 0)
                        {
                            isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstinsAcc.First().InstagramId, lstinsAcc.First().InsUserName, userId, lstinsAcc.First().ProfileUrl, Domain.Socioboard.Enum.SocialProfileType.Instagram, dbr);
                            if (isSaved == 1)
                            {
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);

                                GetInstagramSelfFeeds(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _redisCache, dbr);
                                GetInstagramFollowing(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                GetInstagramFollower(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                new Thread(delegate()
                                {
                                    GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                    GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                }).Start();

                                return("Added_Successfully");
                            }
                        }
                    }
                }
                else
                {
                    objInstagramAccount.id = Instagramaccounts.id;
                    int isSaved = dbr.Update <Domain.Socioboard.Models.Instagramaccounts>(objInstagramAccount);
                    if (isSaved == 1)
                    {
                        List <Domain.Socioboard.Models.Instagramaccounts> lstinsAcc = dbr.Find <Domain.Socioboard.Models.Instagramaccounts>(t => t.InstagramId.Equals(objInstagramAccount.InstagramId)).ToList();
                        if (lstinsAcc != null && lstinsAcc.Count() > 0)
                        {
                            isSaved = GroupProfilesRepository.AddGroupProfile(groupId, lstinsAcc.First().InstagramId, lstinsAcc.First().InsUserName, userId, lstinsAcc.First().ProfileUrl, Domain.Socioboard.Enum.SocialProfileType.Instagram, dbr);
                            if (isSaved == 1)
                            {
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheUserProfileCount + userId);
                                _redisCache.Delete(Domain.Socioboard.Consatants.SocioboardConsts.CacheGroupProfiles + groupId);


                                //todo : codes to update feeds
                                GetInstagramSelfFeeds(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _redisCache, dbr);
                                GetInstagramFollowing(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                GetInstagramFollower(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                new Thread(delegate()
                                {
                                    GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1, _appSettings);
                                    GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, _appSettings);
                                }).Start();



                                return("Added_Successfully");
                            }
                        }
                    }
                }
            }
            return("issue in access token fetching");

            #endregion
        }
        public void GetInstagramFeeds(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            int I = 0;
            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                InstagramResponse<InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "20", objInsAccount.AccessToken);
                InstagramResponse<Comment[]> usercmts = new InstagramResponse<Comment[]>();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed = new Domain.Myfashion.Domain.InstagramFeed();
                CommentController objComment = new CommentController();
                LikesController objLikes = new LikesController();
                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch { }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();
                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else { objInstagramFeed.IsLike = 1; }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = userinf2.data[j].caption.text;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = userinf2.data[j].link;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch { }
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                I++;
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                                logger.Error("GetInstagramFeedsCount>>>"+I);
                            }

                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.EntryDate = DateTime.Now;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FeedId = userinf2.data[j].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.Id = Guid.NewGuid();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.UserId = objInsAccount.UserId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Ejemplo n.º 33
0
        public void getAccessToken()
        {
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"].ToString(), ConfigurationManager.AppSettings["InstagramClientSec"].ToString(), ConfigurationManager.AppSettings["InstagramCallBackURL"].ToString(), "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            SocialProfile            socioprofile     = new SocialProfile();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();
            string      code   = Request.QueryString["code"].ToString();

            SocioBoard.Domain.User user = (SocioBoard.Domain.User)Session["LoggedUser"];
            access = _api.AuthGetAccessToken(code);

            UserController objusercontroller = new UserController();
            InstagramResponse <GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

            InstagramAccount objInsAccount = new InstagramAccount();

            objInsAccount.AccessToken = access.access_token;
            //objInsAccount.FollowedBy=access.user.
            objInsAccount.InstagramId = access.user.id;
            objInsAccount.ProfileUrl  = access.user.profile_picture;
            objInsAccount.InsUserName = access.user.username;
            objInsAccount.TotalImages = objuser.data.counts.media;
            objInsAccount.FollowedBy  = objuser.data.counts.followed_by;
            objInsAccount.Followers   = objuser.data.counts.follows;
            objInsAccount.UserId      = user.Id;

            socioprofile.UserId        = user.Id;
            socioprofile.ProfileType   = "instagram";
            socioprofile.ProfileId     = access.user.id;
            socioprofile.ProfileStatus = 1;
            socioprofile.ProfileDate   = DateTime.Now;
            socioprofile.Id            = Guid.NewGuid();

            if (objInsRepo.checkInstagramUserExists(access.user.id, user.Id))
            {
                HttpContext.Current.Session["alreadyexist"] = objInsAccount;
                objInsRepo.updateInstagramUser(objInsAccount);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
            }
            else
            {
                objInsRepo.addInstagramUser(objInsAccount);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                    GroupRepository        objGroupRepository = new GroupRepository();
                    SocioBoard.Domain.Team team = (SocioBoard.Domain.Team)HttpContext.Current.Session["GroupName"];
                    Groups lstDetails           = objGroupRepository.getGroupName(team.GroupId);
                    if (lstDetails.GroupName == "Socioboard")
                    {
                        TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository();
                        TeamMemberProfile           teammemberprofile = new TeamMemberProfile();
                        teammemberprofile.Id               = Guid.NewGuid();
                        teammemberprofile.TeamId           = team.Id;
                        teammemberprofile.ProfileId        = socioprofile.ProfileId;
                        teammemberprofile.ProfileType      = "instagram";
                        teammemberprofile.StatusUpdateDate = DateTime.Now;

                        objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                    }
                }
            }
            string messages = getIntagramImages(objInsAccount);


            Response.Write(messages);
        }
        private static void GetParseInstagramSelfFeeds(string instagramId, string accessToken)
        {
            var instagramFeedRepo = new MongoRepository("InstagramFeed");

            try
            {
                var _Media     = new Media();
                var usercmts   = new InstagramResponse <Comment[]>();
                var objComment = new CommentController();

                string feeds = _Media.UserResentFeeds(instagramId, accessToken);
                if (feeds != null)
                {
                    apiHitsCount++;
                    JObject feed_data = JObject.Parse(feeds);

                    foreach (var item in feed_data["data"])
                    {
                        try
                        {
                            var objInstagramFeed = new InstagramFeed();

                            objInstagramFeed.FeedDate = Convert.ToDouble(item.SelectToken("created_time")?.ToString() ?? "0");
                            objInstagramFeed.FeedId   = item.SelectToken("id")?.ToString();
                            objInstagramFeed.Type     = item.SelectToken("type")?.ToString();
                            if (objInstagramFeed.Type == "video")
                            {
                                objInstagramFeed.VideoUrl = item.SelectToken("videos.standard_resolution.url")?.ToString();
                            }
                            objInstagramFeed.FeedImageUrl = item.SelectToken("images.standard_resolution.url")?.ToString();
                            objInstagramFeed.InstagramId  = instagramId;
                            objInstagramFeed.LikeCount    = Int32.Parse(item.SelectToken("likes.count")?.ToString() ?? "0");
                            objInstagramFeed.CommentCount = Int32.Parse(item.SelectToken("comments.count")?.ToString() ?? "0");
                            string str = item.SelectToken("user_has_liked")?.ToString();
                            if (str.ToLower() == "false")
                            {
                                objInstagramFeed.IsLike = 0;
                            }
                            else
                            {
                                objInstagramFeed.IsLike = 1;
                            }
                            objInstagramFeed.AdminUser = item.SelectToken("user.username")?.ToString();
                            objInstagramFeed.Feed      = item.SelectToken("caption.text")?.ToString();
                            objInstagramFeed.ImageUrl  = item.SelectToken("user.profile_picture")?.ToString();
                            objInstagramFeed.FromId    = item.SelectToken("user.id")?.ToString();
                            objInstagramFeed.FeedUrl   = item.SelectToken("link")?.ToString();


                            var lstInstagramComment = new List <InstagramComment>();
                            usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken);

                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    var objInstagramComment = new InstagramComment();

                                    objInstagramComment.Comment        = usercmts?.data[cmt]?.text ?? "0";
                                    objInstagramComment.CommentDate    = Convert.ToDouble(usercmts?.data[cmt]?.created_time.ToString() ?? "0");
                                    objInstagramComment.CommentId      = usercmts?.data[cmt]?.id ?? "";
                                    objInstagramComment.FeedId         = objInstagramFeed?.FeedId ?? "";
                                    objInstagramComment.InstagramId    = instagramId;
                                    objInstagramComment.FromName       = usercmts?.data[cmt]?.from?.username ?? "";
                                    objInstagramComment.FromProfilePic = usercmts?.data[cmt]?.from?.profile_picture ?? "";

                                    lstInstagramComment.Add(objInstagramComment);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            objInstagramFeed._InstagramComment = lstInstagramComment;
                            var ret  = instagramFeedRepo.Find <InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
                            var task = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            int count = task.Result.Count;

                            if (count < 1)
                            {
                                instagramFeedRepo.Add(objInstagramFeed);
                            }
                            else
                            {
                                var filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
                                var update = Builders <BsonDocument> .Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl).Set("_InstagramComment", objInstagramFeed._InstagramComment);

                                instagramFeedRepo.Update <InstagramFeed>(update, filter);
                            }
                        }
                        catch (Exception ex)
                        {
                            apiHitsCount = MaxapiHitsCount;
                        }
                    }
                }
                else
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
            }
        }