public async Task <IHttpActionResult> GetMidiasByGeoLocation(Double numLati, Double numLong, String desLocal)
        {
            try
            {
                RepositoryDataAccessInstagram repo = new RepositoryDataAccessInstagram();
                var auth = new OAuth();

                OAuthResponse oauthResponse;

                var dataAccess = repo.GetIsValid();

                if (dataAccess != null)
                {
                    oauthResponse = dataAccess.Map <DataAccessInstagram, OAuthResponse>();
                }
                else
                {
                    LogonInstagram logon = new LogonInstagram();
                    var            token = await logon.GetToken();

                    oauthResponse = await auth.RequestToken(token);

                    if (oauthResponse != null)
                    {
                        var data = oauthResponse.Map <OAuthResponse, DataAccessInstagram>();

                        if (data != null)
                        {
                            repo.Save(data);
                        }
                    }
                }

                var midia  = new Hackathon.Instagram.Core.EndPoint.Media(auth.Config, oauthResponse);
                var result = await midia.Search(numLati, numLong);

                if (String.IsNullOrEmpty(desLocal))
                {
                    return(Ok(result.Data));
                }
                else
                {
                    var data = result.Data.Where(x => x.Location != null && x.Location.Name.Contains(desLocal)).ToList();
                    return(Ok(data));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("An has ocorred : " + ex.Message));
            }
        }
        public async Task <IHttpActionResult> GetVideoByGeoLocation(Double numLati, Double numLong, String desLocal)
        {
            try
            {
                RepositoryDataAccessInstagram repo = new RepositoryDataAccessInstagram();
                var auth = new OAuth();

                OAuthResponse oauthResponse;

                var dataAccess = repo.GetIsValid();

                if (dataAccess != null)
                {
                    oauthResponse = dataAccess.Map <DataAccessInstagram, OAuthResponse>();
                }
                else
                {
                    LogonInstagram logon = new LogonInstagram();
                    var            token = await logon.GetToken();

                    oauthResponse = await auth.RequestToken(token);

                    if (oauthResponse != null)
                    {
                        var data = oauthResponse.Map <OAuthResponse, DataAccessInstagram>();

                        if (data != null)
                        {
                            repo.Save(data);
                        }
                    }
                }

                var midia  = new Hackathon.Instagram.Core.EndPoint.Media(auth.Config, oauthResponse);
                var result = await midia.Search(numLati, numLong);

                var videos = this.GetOnlyVideos(result.Data, desLocal);

                return(Ok(videos));
            }
            catch (Exception ex)
            {
                return(BadRequest("An has ocorred : " + ex.Message));
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Index()
        {
            RepositoryDataAccessInstagram repo = new RepositoryDataAccessInstagram();
            var           auth = new OAuth();
            OAuthResponse oauthResponse;

            var dataAccess = repo.GetIsValid();

            if (dataAccess != null)
            {
                oauthResponse = dataAccess.Map <DataAccessInstagram, OAuthResponse>();
            }
            else
            {
                LogonInstagram logon = new LogonInstagram();
                var            token = await logon.GetToken();

                oauthResponse = await auth.RequestToken(token);

                if (oauthResponse != null)
                {
                    var data = oauthResponse.Map <OAuthResponse, DataAccessInstagram>();

                    if (data != null)
                    {
                        repo.Save(data);
                    }
                }
            }

            if (oauthResponse == null)
            {
                return(Redirect(auth.AuthLink()));
            }
            else
            {
                return(View(oauthResponse.User));
            }
        }