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); }
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; }
public string InstagramSingleUser(string UserId) { string response = string.Empty; try { GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", "f5f052ccbdf94df490020f852863141b", "6c8ac0efa42c4c918bf33835fc98a793", "http://localhost:9821/InstagramManager/Instagram", "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", ""); oAuthInstagram _api = new oAuthInstagram(); _api = oAuthInstagram.GetInstance(configi); AccessToken access = new AccessToken(); //ArrayList arrList = instagramRepo.getAllInstagramAccounts(); //Domain.Socioboard.Domain.InstagramAccount instaacc = (Domain.Socioboard.Domain.InstagramAccount)arrList[1]; //string tk = instaacc.AccessToken; string tk = "422418207.d89b5cf.7d26304ef400404d816218f2318f6cc6"; response = _api.WebRequest(oAuthInstagram.Method.GET, "https://api.instagram.com/v1/users/" + UserId + "/?access_token=" + tk, null); } catch (Exception ex) { } return response; }
public string InstagramSearch(string keyword, string WebUrl) { string response = string.Empty; string resId = string.Empty; try { GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", "f5f052ccbdf94df490020f852863141b", "6c8ac0efa42c4c918bf33835fc98a793", "http://localhost:9821/InstagramManager/Instagram", "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", ""); oAuthInstagram _api = new oAuthInstagram(); _api = oAuthInstagram.GetInstance(configi); AccessToken access = new AccessToken(); //ArrayList arrList = instagramRepo.getAllInstagramAccounts(); //Domain.Socioboard.Domain.InstagramAccount instaacc = (Domain.Socioboard.Domain.InstagramAccount)arrList[0]; //string tk = instaacc.AccessToken; string tk = "422418207.d89b5cf.7d26304ef400404d816218f2318f6cc6"; //TODO : Access token Logic response = _api.WebRequest(oAuthInstagram.Method.GET, "https://api.instagram.com/v1/users/search?q=" + keyword + "&access_token=" + tk, null); if (!response.StartsWith("[")) response = "[" + response + "]"; JArray Instagramaccarray = JArray.Parse(response); foreach (var acc in Instagramaccarray) { var data = acc["data"]; foreach (var page in data) { try { if (page["website"].ToString().Equals(WebUrl)) { resId = page["id"].ToString(); break; } } catch (Exception e) { } } } } catch (Exception ex) { } if (string.IsNullOrEmpty(resId)) { return string.Empty; } return InstagramSingleUser(resId); }
public static string Serialize(AccessToken token) { string json = Base.SerializeObject(token); return json; }
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; }