Ejemplo n.º 1
0
        // GET: Instagram
        public ActionResult Index()
        {
            HomeModel userModel     = new HomeModel();
            Users     userEndpoints = new Users();

            if (!Request.IsAuthenticated)
            {
                var code = Request.QueryString["code"];
                if (!string.IsNullOrEmpty(code))
                {
                    InstagramAuth instagramAuth   = new InstagramAuth();
                    InstaConfig   instagramConfig = new InstaConfig();
                    instagramConfig.redirect_uri  = "http://localhost:58065/Instagram/Index";
                    instagramConfig.client_secret = "f975c1bf53f64aecb7bf63dda0d996d7";
                    instagramConfig.client_id     = "01b344efcdb445068a20f30391bea917";
                    userModel.user = instagramAuth.GetAccessToken(code, instagramConfig);

                    FormsAuthentication.SetAuthCookie(userModel.user.access_token, true);
                    userModel.UserFeed  = userEndpoints.GetUserMedia("2368860595", userModel.user.access_token);
                    ViewBag.UserProfile = userEndpoints.GetUserSelf(userModel.user.access_token).data;
                }
            }
            else
            {
                userModel.user = new OuthUser();
                userModel.user.access_token = HttpContext.User.Identity.Name;
                ViewBag.UserProfile         = userEndpoints.GetUserSelf(userModel.user.access_token).data;
                userModel.UserFeed          = userEndpoints.GetUserMedia("2368860595", userModel.user.access_token);
            }
            return(View(userModel.UserFeed));
        }
        //
        // GET: /Instagram/

        public ActionResult Index()
        {
            HomeModel mdl = new HomeModel();

            mdl.profilmodel = new ProfileModel();
            Users usr = new Users();

            if (!Request.IsAuthenticated)
            {
                var code = Request.QueryString["code"];
                if (!string.IsNullOrEmpty(code))
                {
                    InstagramAuth ia = new InstagramAuth();
                    InstaConfig   ic = new InstaConfig();
                    ic.redirect_uri  = "http://localhost:51963/Instagram";
                    ic.client_secret = "";
                    ic.client_id     = "";
                    mdl.user         = ia.GetAccessToken(code, ic);
                    FormsAuthentication.SetAuthCookie(mdl.user.access_token, true);
                    mdl.UserFeed = usr.GetUserSelfFeed(mdl.user.access_token);
                }
            }
            else
            {
                mdl.user = new OuthUser();
                mdl.user.access_token  = HttpContext.User.Identity.Name;
                mdl.user.user          = usr.GetUserSelf(mdl.user.access_token).data;
                mdl.UserFeed           = usr.GetUserSelfFeed(mdl.user.access_token);
                mdl.profilmodel.counts = mdl.user.user.counts;
            }
            mdl.pagetype = "home";
            return(View(mdl));
        }
Ejemplo n.º 3
0
        public OuthUser GetAccessToken(string code, InstaConfig ic)
        {
            var client = new HttpClient();

            var postData = new List <KeyValuePair <string, string> >();

            postData.Add(new KeyValuePair <string, string>("client_id", ic.client_id));
            postData.Add(new KeyValuePair <string, string>("client_secret", ic.client_secret));
            postData.Add(new KeyValuePair <string, string>("grant_type", "authorization_code"));
            postData.Add(new KeyValuePair <string, string>("redirect_uri", ic.redirect_uri));
            postData.Add(new KeyValuePair <string, string>("code", code));
            HttpContent content = new FormUrlEncodedContent(postData);


            var      rslt   = client.PostAsync("https://api.instagram.com/oauth/access_token", content).Result;
            var      result = rslt.Content.ReadAsStringAsync().Result;
            OuthUser aa     = JsonConvert.DeserializeObject <OuthUser>(result);

            return(aa);
        }
Ejemplo n.º 4
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig and AuthUser</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public Location(InstaConfig Config, AuthUser AuthorisedUser)
        {
            this.Config         = Config;
            this.AuthorisedUser = AuthorisedUser;
        }
Ejemplo n.º 5
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig and AuthUser</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public Relationships(InstaConfig Config, AuthUser AuthorisedUser)
        {
            this.Config         = Config;
            this.AuthorisedUser = AuthorisedUser;
        }
Ejemplo n.º 6
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig and AuthUser</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public Tags(InstaConfig Config, AuthUser AuthorisedUser)
        {
            this.Config         = Config;
            this.AuthorisedUser = AuthorisedUser;
        }
Ejemplo n.º 7
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public UnLocation(InstaConfig Config)
        {
            this.Config = Config;
        }
Ejemplo n.º 8
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig</para>
        /// </summary>
        /// <param name="Config"></param>
        public UnMedia(InstaConfig Config)
        {
            this.Config = Config;
        }
Ejemplo n.º 9
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public UnTags(InstaConfig Config)
        {
            this.Config = Config;
        }
Ejemplo n.º 10
0
        /****************************************************** CONSTRUCTORS *******************************************************/

        /// <summary>
        ///     <para>instantiate with InstaConfig</para>
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="AuthorisedUser"></param>
        public UnUsers(InstaConfig Config)
        {
            this.Config = Config;
        }