Ejemplo n.º 1
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))
            {
                objInsRepo.updateInstagramUser(objInsAccount);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
            }
            else
            {
                objInsRepo.addInstagramUser(objInsAccount);
                if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                {
                    socioprofilerepo.addNewProfileForUser(socioprofile);
                }
            }
       string messages =     getIntagramImages(objInsAccount);

          
            Response.Write(messages);
        }
Ejemplo n.º 2
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);

            


            UserController objusercontroller = new UserController();
            try
            {
                logger.Error("AddInstagramAccount == >>" + access.access_token);
                #region InstagramAccount
                InstagramResponse<GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);

                objInstagramAccount = new Domain.Socioboard.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.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    //Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.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);

                    Domain.Socioboard.Domain.GroupProfile grpProfile = new Domain.Socioboard.Domain.GroupProfile();
                    grpProfile.Id = Guid.NewGuid();
                    grpProfile.EntryDate = DateTime.UtcNow;
                    grpProfile.GroupId = Guid.Parse(GroupId);
                    grpProfile.GroupOwnerId = Guid.Parse(UserId);
                    grpProfile.ProfileId = objInstagramAccount.InstagramId;
                    grpProfile.ProfileType = "instagram";
                    grpProfile.ProfileName = objInstagramAccount.InsUserName;
                    grpProfile.ProfilePic = objInstagramAccount.ProfileUrl;
                    grpProfileRepo.AddGroupProfile(grpProfile);




                    #endregion
                    #region SocialProfile
                    Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.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);

                GetInstagramUserDetails(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
                GetInstagramFollowing(objInstagramAccount.UserId.ToString(), objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramFollower(objInstagramAccount.UserId.ToString(), objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramPostLikes(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken, 1);
                GetInstagramPostComments(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
                //GetInstagramUserPosts(objInstagramAccount.InstagramId, objInstagramAccount.AccessToken);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            return ret;
        }
Ejemplo n.º 3
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.Socioboard.Domain.InstagramAccount();
            objInstagramAccount.AccessToken = access.access_token;
            objInstagramAccount.InstagramId = access.user.id;
            objInstagramAccount.ProfileUrl = access.user.profile_picture;
            objInstagramAccount.InsUserName = access.user.username;
            objInstagramAccount.TotalImages = objuser.data.counts.media;
            objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
            objInstagramAccount.Followers = objuser.data.counts.follows;
            objInstagramAccount.UserId = Guid.Parse(UserId); 
            #endregion


            if (!objInstagramAccountRepository.checkInstagramUserExists(objInstagramAccount.InstagramId,Guid.Parse(UserId)))
                {
                    objInstagramAccountRepository.addInstagramUser(objInstagramAccount);
                    #region Add TeamMemberProfile
                    Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                    Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.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.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.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);
            return ret;
        }