public ActionResult AuthorizeCallback(string code, string userCode) { var redirectUri = "http://" + Request.Url.Authority + this.Url.Action("AuthorizeCallback", new { userCode = userCode }); var sharpSquare = new SharpSquare(clientID, clientSecret); var accessToken = sharpSquare.GetAccessToken(redirectUri, code); // need this in order to make calls to API // it's redundant because token is already set in GetAccessToken() call but it helps to understand the workflow better. UserLoginInfo u1 = new UserLoginInfo(); using (CheckinDatasetEntities4 db = new CheckinDatasetEntities4()) { var UserLogID = (from p in db.UserLoginInfo where p.USERNAME == User.Identity.Name select p.USERLOGINID).FirstOrDefault(); string token = accessToken; db.Token.Add(new Token() { TOKENACID = token, USERLOGINID = UserLogID }); db.SaveChanges(); } //CheckinOperations.insertUSerLoginInfo(u1); return(RedirectToAction("Index", "Home")); }
protected void Session_Start(object sender, EventArgs e) { var request = HttpContext.Current.Request; var uriBuilder = new UriBuilder { Host = request.Url.Host, Path = "/Home/Index", Port = 80, Scheme = "http", }; if (request.IsLocal) { uriBuilder.Port = request.Url.Port; } var redirectUri = uriBuilder.Uri.AbsoluteUri; // Code that runs when a new session is started if (HttpContext.Current.Session["SharpSquare"] != null) return; Logger.Error("redirectUri:" + redirectUri); var sharpSquare = new SharpSquare(ClientId, ClientSecret); var autenticateUrl = sharpSquare.GetAuthenticateUrl(redirectUri); Session["AutenticateUrl"] = autenticateUrl; Session["RedirectUri"] = redirectUri; Session["SharpSquare"] = sharpSquare; }
public VenuesService() { var clientId = WebConfigurationManager.AppSettings["FourSquareClientID"]; var clientSecret = WebConfigurationManager.AppSettings["FourSquareClientSecret"]; this._queryService = new SearchQueryService(); this._sharpSquare = new SharpSquare(clientId, clientSecret); }
public HomeService() { this._clientId = WebConfigurationManager.AppSettings[HomeConstant.ClientId]; this._clientSecret = WebConfigurationManager.AppSettings[HomeConstant.ClientSecret]; this._sharpSquare = new SharpSquare(this._clientId, this._clientSecret); this._db = new FoursquareClientAssignmentContext(); }
public ActionResult UserClicksAuthenticate() { var redirectUri = "http://" + Request.Url.Authority + this.Url.Action("AuthorizeCallback", new { userCode = "userCode" }); //var redirectUri = "http://www.muhammetkaya.com/redirect_url" + this.Url.Action("AuthorizeCallback", new { userCode = "userCode" }); var sharpSquare = new SharpSquare(clientID, clientSecret); var authUrl = sharpSquare.GetAuthenticateUrl(redirectUri); return(new RedirectResult(authUrl, permanent: false)); }
public FoursquareHelper(string clientId, string clientSecret) { try { _sharpSquare = new SharpSquare(clientId, clientSecret); } catch (Exception ex) { _logger.Error(ex.Message); throw; } }
private List <Venue> GetBarData(string latitude, string longitude, string radius) { var sharpSquare = new SharpSquare(clientId, clientSecret); // let's build the query Dictionary <string, string> parameters = new Dictionary <string, string> { { "ll", latitude + "," + longitude }, // Coords { "radius", radius }, { "categoryId", categoryIdBar } }; return(sharpSquare.SearchVenues(parameters)); }
public void handleCallback() { try { string clientId = "CLIENT_ID"; string clientSecret = "CLIEND_SECRET"; string redirectUri = "REDIRECT_URI"; SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret); sharpSquare.GetAuthenticateUrl(redirectUri); } catch (Exception e) { } }
public virtual ActionResult Authorize(string code) { if (string.IsNullOrWhiteSpace(code)) { return Json("Failed to authenticate"); } var api = new SharpSquare(ClientId, ClientSecret); string token = api.GetAccessToken(RedirectUrl, code); api.SetAccessToken(token); var user = api.GetUser(); // todo store token to user using(var context = new FourWarContext()) { /* var user = context.Users.Create(); user.OAuthToken = token; user * */ } return RedirectToAction(MVC.Home.Index()); }
public ActionResult venues() { SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret); BancoContext db = new BancoContext(); int lastid = 0; Dictionary<string, string> parametros = new Dictionary<string, string>(); List<Banco.Models.Venue> lisVenue = db.Venues.Where(w => w.updated.Year < 1950).ToList(); foreach (Banco.Models.Venue ven in lisVenue) { try { FourSquare.SharpSquare.Entities.Venue v = new FourSquare.SharpSquare.Entities.Venue(); lastid = ven.Id; v = sharpSquare.GetVenue(ven.SquareId); ven.checkincount = (int)v.stats.checkinsCount; ven.tipcount = (int)v.stats.tipCount; ven.rate = v.rating; if (v.price != null) ven.tier = v.price.tier; ven.likes = (int)v.likes.count; ven.updated = DateTime.Now; db.SaveChanges(); } catch (Exception e) { if (e.Message == "O servidor remoto retornou um erro: (403) Proibido.") { ViewBag.Message = e.Message; break; } } } return View(); }
public virtual ActionResult Authenticate() { var api = new SharpSquare(ClientId, ClientSecret); string authenticateUrl = api.GetAuthenticateUrl(RedirectUrl); return Redirect(authenticateUrl); }
public PlaceController() { _placeService = new PlaceService(); _FSClient = new SharpSquare(ConfigurationManager.AppSettings["FourSquareClientId"], ConfigurationManager.AppSettings["FourSquareClientSecret"]); }
public FourSquareService(IOptions <FourSquareOptions> options) { _sharpSquare = new SharpSquare(options.Value.Smartbot_Foursquare_ClientId, options.Value.Smartbot_Foursquare_ClientSecret); }
public ActionResult PreencherUsuarios() { SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret); BancoContext db = new BancoContext(); int lastid = 13027; Dictionary<string, string> parametros = new Dictionary<string, string>(); List<Banco.Models.User> lisUser = db.Users.Where(w => w.Sexo == null && w.Id > lastid).ToList(); foreach (Banco.Models.User usuario in lisUser) { try { FourSquare.SharpSquare.Entities.User us = new FourSquare.SharpSquare.Entities.User(); lastid = usuario.Id; us = sharpSquare.GetUser(usuario.SquareId); usuario.Sexo = us.gender; usuario.countAmigos = (int)us.friends.count; usuario.countCheckin = (int)us.checkins.count; usuario.countTip = (int)us.tips.count; usuario.cidadeNatal = us.homeCity; db.SaveChanges(); } catch (Exception e) { if (e.Message == "O servidor remoto retornou um erro: (403) Proibido.") { break; } } } return View(); }
public ActionResult PreencheCategorias() { SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret); List<Banco.Models.Venue> venues = db.Venues.Include("Categories").Where(w => w.Id > 5734).ToList(); foreach (Banco.Models.Venue v in venues) { if (v.Categories == null || v.Categories.Count == 0) { FourSquare.SharpSquare.Entities.Venue venSquare = sharpSquare.GetVenue(v.SquareId); if (venSquare.categories != null) { foreach (FourSquare.SharpSquare.Entities.Category c in venSquare.categories) { Banco.Models.Category cat; cat = db.Categories.FirstOrDefault(f => f.SquareId == c.id); if (cat == null) { cat = new Banco.Models.Category(); cat.Name = c.name; cat.SquareId = c.id; v.Categories.Add(cat); } else { if (v.Categories.Where(w => w.SquareId == c.id) == null || v.Categories.Where(w => w.SquareId == c.id).Count() == 0) { v.Categories.Add(cat); } } db.SaveChanges(); } } } } ViewBag.Message = "Preenche Categorias dos estabelecimentos."; return View(); }
public ActionResult AdicionarTips() { SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret); List<Banco.Models.Tip> tiplist = new List<Banco.Models.Tip>(); List<Banco.Models.User> userlist = new List<Banco.Models.User>(); List<Banco.Models.Venue> venuelist = new List<Banco.Models.Venue>(); Dictionary<string, string> parametros = new Dictionary<string, string>(); List<FourSquare.SharpSquare.Entities.Venue> venues = new List<FourSquare.SharpSquare.Entities.Venue>(); List<FourSquare.SharpSquare.Entities.Tip> tips = new List<FourSquare.SharpSquare.Entities.Tip>(); parametros.Add("limit", "500"); // tentando pegar ateh 500 venues e tips for (double lon = -43.2652; lon < -43.2475; lon += 0.0005) { parametros.Remove("limit"); parametros.Add("limit", "50"); parametros.Add("ll", "-22.8707," + lon.ToString().Replace(',', '.')); venues = sharpSquare.SearchVenues(parametros); foreach (FourSquare.SharpSquare.Entities.Venue v in venues) { Banco.Models.Venue ven; ven = db.Venues.FirstOrDefault(f => f.SquareId == v.id); if (ven == null && venuelist.FirstOrDefault(f => f.SquareId == v.id) == null) { ven = new Banco.Models.Venue(); ven.SquareId = v.id; ven.lat = -22.8707; ven.lon = lon; venuelist.Add(ven); db.Venues.Add(ven); } ven.Name = v.name; parametros.Remove("ll"); parametros.Remove("limit"); parametros.Add("limit", "500"); tips = sharpSquare.GetVenueTips(v.id, parametros); foreach (FourSquare.SharpSquare.Entities.Tip t in tips) { Banco.Models.Tip tip; //Verifica de tip já foi adicionada anteriormente no banco tip = db.Tips.FirstOrDefault(f => f.SquareId == t.id); if (tip == null && tiplist.FirstOrDefault(f => f.SquareId == t.id) == null) { //Se é uma tip nova cria uma e adiciona no context tip = new Banco.Models.Tip(); tip.SquareId = t.id; tip.Venue = ven; tiplist.Add(tip); db.Tips.Add(tip); } //sendo tip nova ou não atualiza os campos tip.Description = t.text; Banco.Models.User user; user = db.Users.FirstOrDefault(f => f.SquareId == t.user.id); if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) == null) { user = new Banco.Models.User(); user.SquareId = t.user.id; user.Name = t.user.firstName; userlist.Add(user); db.Users.Add(user); } if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) != null) { user = userlist.FirstOrDefault(f => f.SquareId == t.user.id); } tip.User = user; } } db.SaveChanges(); } ViewBag.Message = "Venues, tips e users adicionados ao banco com sucesso."; return View(); }
public FoursquareClient(IProvideFoursquareConfiguration configuration) { this.configuration = configuration; client = new SharpSquare(configuration.ClientId, configuration.ClientSecret); }
public FourSquareService(string clientId, string clientSecret) { _sharpSquare = new SharpSquare(clientId, clientSecret); }
public List<FourSquareDataModel.Venue> GetVenuesNearBuilding(string modelId, string buildingId) { if (!IW360OAuth.IsAuthorized) return null; Building building = GetModelBuilding(modelId, buildingId); if (building.geometry.Type != AiwGeometryType.Polygon) return null; // from the polygon of the building on IW360, // let calculate the center point (avarage) AiwPolygon pl = building.geometry as AiwPolygon; int i = 0; double avarageLat = 0; double avarageLng = 0; foreach (AiwLineString ls in pl.LinearRings) { foreach (AiwCoordinate coord in ls.Coordinates) { avarageLat += coord.Y; avarageLng += coord.X; i++; } } avarageLat /= i; avarageLng /= i; // now use the avarage point to get venus from Four Square SharpSquare square = new SharpSquare(FOURSQUARE_CLIENTID, FOURSQUARE_CLIENTSECRET); Dictionary<string, string> requestParams = new Dictionary<string, string>(); requestParams.Add("ll", string.Format(new CultureInfo("en-US"), "{0},{1}", avarageLat, avarageLng)); requestParams.Add("radius", "500"); requestParams.Add("intent", "browse"); List<Venue> venues = square.SearchVenues(requestParams); // the venus from Four Square will come with lots of data // let's simplify and add some interesting data List<FourSquareDataModel.Venue> simplifiedVenues = new List<FourSquareDataModel.Venue>(); foreach (Venue v in venues) { FourSquareDataModel.Venue venueSummary = new FourSquareDataModel.Venue(); venueSummary.name = v.name; venueSummary.id = v.id; venueSummary.distance = v.location.distance; venueSummary.address = v.location.address; venueSummary.url = v.url; venueSummary.foursqlat = v.location.lat; venueSummary.foursqlng = v.location.lng; venueSummary.iw360lat = avarageLat; venueSummary.iw360lng = avarageLng; simplifiedVenues.Add(venueSummary); } // and finally order by distance from the center of the building var simplifiedVenuesOrder = from FourSquareDataModel.Venue v in simplifiedVenues orderby v.distance ascending select v; return simplifiedVenuesOrder.ToList(); // will serialize to JSON }
public FourSquareService() { _FourSquare = new SharpSquare(_ClientId, _ClientSecret); }
//private List<object> GetFriends(SharpSquare sharpSquare) private SharpSquare GetClient() { var sharpSquare = new SharpSquare(FourSquareClientId, FourSquareClientSecret); sharpSquare.SetAccessToken(FourSquareOAuthToken); return sharpSquare; }
private List<Venue> GetVenues(SharpSquare sharpSquare, string latitude, string longitude, string type) { var parameters = new Dictionary<string, string> { {"ll", string.Join(",", latitude, longitude)}, {"categoryId", m_eventTypes[type.ToLower()]} }; return sharpSquare.SearchVenues(parameters); }
public FourSquareFactory() { _sharpSquareClient = new SharpSquare(clientId, clientSecret); }
public Swarm(string clientID, string clientSecret) { this.ClientID = clientID; this.ClientSecret = clientSecret; client = new SharpSquare(ClientID, ClientSecret); }