public void Initialize()
 {
     _api = new Api(new CachedSession(Constants.FBSamples_ApplicationKey, Constants.FBSamples_SessionSecret, Constants.FBSamples_SessionKey));
     _api.Session.UserId = Constants.FBSamples_UserId;
     _apiWeb = new Api(new TestSession(Constants.FBSamples_WebApplicationKey, Constants.FBSamples_WebSecret));
     _apiWeb.Session.UserId = Constants.FBSamples_UserId;
 }
예제 #2
0
 private static BaseAuthenticationInfo LocateFacebookResponse()
 {
     FacebookAuthenticationInfo authInformation = null;
     var connectSession = new ConnectSession(Constants.FacebookApplicationKey, Constants.FacebookApplicationSecret);
     if (connectSession.IsConnected())
     {
         var facebookApi = new Api(connectSession);
         try
         {
             var userInfo = facebookApi.Users.GetInfo();
             authInformation = new FacebookAuthenticationInfo();
             authInformation.Identifier = userInfo.uid.HasValue ? userInfo.uid.Value.ToString() : String.Empty;
             authInformation.FirstName = userInfo.first_name;
             authInformation.LastName = userInfo.last_name;
             authInformation.Email = userInfo.proxied_email;
             authInformation.UserName = userInfo.name;
             authInformation.Provider = providerModule.GetProvider("Facebook");
             authInformation.Picture = userInfo.pic;
             facebookApi.Auth.ExpireSession();
             return authInformation;
         }
         catch (FacebookException ex)
         {
             return null;
         }
     }
     return authInformation;
 }
 /// <summary>
 /// Logs in user
 /// </summary>
 public string GetNextUrl()
 {
     var props = new Api().Initialize(this).Admin.GetAppProperties(new List<string>() { "callback_url", "canvas_name" });
     if (props.ContainsKey("callback_url") && props.ContainsKey("canvas_name") && !string.IsNullOrEmpty(props["callback_url"]) && !string.IsNullOrEmpty(props["callback_url"]))
     {
         return HttpContext.Current.Request.Url.ToString().Replace(props["callback_url"], string.Format("http://apps.facebook.com/{0}/", props["canvas_name"]));
     }
     return null;
 }
예제 #4
0
    new protected void Page_Load(object sender, EventArgs e)
    {
        CanvasSession fs = new Facebook.Session.FBMLCanvasSession(
            ConfigurationSettings.AppSettings["APIKey"].ToString(),
            ConfigurationSettings.AppSettings["Secret"].ToString()
            );
        Api  api    = new Facebook.Rest.Api(fs);
        user fbUser = api.Users.GetInfo();      // Uygulamayi kullanan kullanicinin bilgileri

        UserFbId = fbUser.uid.ToString();
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     connectSession = new Facebook.Session.ConnectSession(ConfigurationManager.AppSettings["ApiKey"], ConfigurationManager.AppSettings["Secret"]);
     if (!connectSession.IsConnected())
     {
     }
     else
     {
         api = new Facebook.Rest.Api(connectSession);
         Facebook.Schema.user u = api.Users.GetInfo();
     }
 }
예제 #6
0
        public ActionResult Index()
        {
            ConnectSession session = new ConnectSession(ConfigurationManager.AppSettings["Facebook_API_Key"], ConfigurationManager.AppSettings["Facebook_API_Secret"]);
            if(session.IsConnected())
            {
                Api facebook = new Api(session);

                ViewData["Message"] = "Hello, " + facebook.Users.GetInfo().name;
            }
            else
            {
                ViewData["Message"] = "Login with Facebook!";
            }

            return View();
        }
예제 #7
0
 private void EnsureApi()
 {
     if (api != null) return;
     EnsureSession();
     api = new Api(session);
 }
예제 #8
0
        public ActionResult Default()
        {
            #region PreviousCoding
            Repository repoObj = new Repository();
            Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
            if (memberData != null)
            {
                //ViewData["LocationData"] = locations;
                //ViewData["Memberlocation"] = memberLocation;
            }
            else
            {
                string logoutString = TempData["Logout"] as string;
                if (logoutString != "Logout")
                {
                    const string myFacebookApiKey = "101151816623334";
                    const string myFacebookSecret = "65f49046dce2d1f54d6991e43c4af675";

                    var connectSession = new ConnectSession(myFacebookApiKey, myFacebookSecret);
                    if (connectSession.IsConnected())
                    {
                        ViewData["FBConnected"] = true;
                        var api = new Api(connectSession);
                        ViewData["FBUser"] = api.Users.GetInfo();
                        ViewData["UserID"] = api.Users.GetInfo().uid;
                        SessionStore.SetSessionValue(SessionStore.FacebookConnect, "FacebookUserLoggedIn");
                        string[] fbDetails = new string[2];
                        fbDetails[0] = Convert.ToString("fb_" + api.Users.GetInfo().uid);
                        fbDetails[1] = api.Users.GetInfo().name;
                        SessionStore.SetSessionValue("FacebookDetails", fbDetails);
                        api.Session.Logout();
                        connectSession.Logout();
                        return RedirectToAction("FBUser", "Member");
                    }
                }
            }
            #endregion

            GetTopPlanters();

            CommonMethods objCmnMethods = new CommonMethods();

            string strIpAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
            if (strIpAddress == "127.0.0.1")
                strIpAddress = "61.246.241.162";

            string citySearch = string.Empty;
            string stateSearch = string.Empty;
            string zipCodeSearch = string.Empty;
            string latSearch = string.Empty;
            string lngSearch = string.Empty;
            string[] currentAddress;

            string ipLocation = objCmnMethods.MaxMindIPData(strIpAddress);
            if (!string.IsNullOrEmpty(ipLocation) && (!ipLocation.Contains("IP_NOT_FOUND")))
            {
                //IPaddressAPI
                currentAddress = ipLocation.Split(',');

                if (string.IsNullOrEmpty(currentAddress[1].Replace("\"", "").ToString()))
                    stateSearch = "AZ";
                else
                {
                    stateSearch = currentAddress[1].Replace("\"", "").ToString();
                    //stateSearch = "WA";
                }

                if (string.IsNullOrEmpty(currentAddress[2].ToString()))
                    citySearch = "Phoenix";
                else
                {
                    citySearch = currentAddress[2].Replace("\"", "").ToString();
                    //citySearch = "Seattle";
                }

                if (string.IsNullOrEmpty(currentAddress[3].Replace("\"", "").ToString()))
                {
                    //zipCodeSearch = "85027";
                    SeedAction objS = new SeedAction();
                    LocationAction objLocation = new LocationAction();
                    string cityId = objLocation.GetCityIdByCityName(citySearch, stateSearch);
                    zipCodeSearch = objS.GetZipOfSeedByCityId(cityId);
                }
                else
                    zipCodeSearch = currentAddress[3].Replace("\"", "").ToString();

                latSearch = currentAddress[4].Replace("\"", "").ToString();
                lngSearch = currentAddress[5].Replace("\"", "").ToString();
            }
            else
            {
                //MaxMind
                ipLocation = objCmnMethods.IP2AddressMaxMind();
                currentAddress = ipLocation.Split('\'');

                if (string.IsNullOrEmpty(currentAddress[7].ToString()))
                    stateSearch = "AZ";
                else
                    stateSearch = currentAddress[7].ToString();

                if (string.IsNullOrEmpty(currentAddress[5].ToString()))
                    citySearch = "Phoenix";
                else
                    citySearch = currentAddress[5].ToString();

                if (string.IsNullOrEmpty(currentAddress[15].ToString()))
                    zipCodeSearch = "85027";
                else
                    zipCodeSearch = currentAddress[15].ToString();

                latSearch = currentAddress[11].ToString();
                lngSearch = currentAddress[13].ToString();
            }

            ViewData["LocLat"] = latSearch;
            ViewData["LocLng"] = lngSearch;
            Session["LocLatLng"] = latSearch + "," + lngSearch;

            SeedAction objSeed = new SeedAction();
            IList<Seed> lstSeed = getHomeSearchResult(citySearch, "", "", zipCodeSearch, "");
            if (lstSeed.Count > 0)
            {
                ViewData["SeedList"] = lstSeed.OrderByDescending(x => x.createDate).ToList();
                ViewData["userLocation"] = "Your Location : " + citySearch + ", " + stateSearch;
                ViewData["CatLocation"] = citySearch + ", " + stateSearch;
            }
            else
            {
                lstSeed = repoObj.List<Seed>().Where(x => x.status.Equals(SystemStatements.STATUS_NEW) || x.status.Equals(SystemStatements.STATUS_GROWING)).OrderByDescending(x => x.createDate).Take(20).ToList();
                ViewData["SeedList"] = lstSeed;
                ViewData["userLocation"] = "Your Location : " + citySearch + ", " + stateSearch;
                ViewData["CatLocation"] = citySearch + ", " + stateSearch;
                ViewData["CitySearchMsg"] = "<span>Sorry, no seeds planted in '" + citySearch + "' area. Showing latest additions.</span>";
                string streamFeed = "Select top 20 * from Seed order by createDate desc";
                SessionStore.SetSessionValue(SessionStore.DefaultFeed, streamFeed);
            }

            string advSearch = TempData["DiscoverSeed"] as string;
            if (advSearch != "AdvanceSearch")
            {
                if (lstSeed.Count > 0)
                    SessionStore.SetSessionValue(SessionStore.DiscoverSeed, lstSeed);
            }

            if (SessionStore.GetSessionValue(SessionStore.DiscoverSeed) != null)
                lstSeed = (IList<Seed>)SessionStore.GetSessionValue(SessionStore.DiscoverSeed);

            int rowCount = lstSeed.Count;
            Session["RowCount"] = rowCount;
            Session["PageCount"] = "1";
            ViewData["SeedList"] = lstSeed.Take(10).ToList();
            ViewData["PrevVisibility"] = "visibility:hidden;";
            if (lstSeed.Count > 10)
                ViewData["NxtVisibility"] = "visibility:visible;";
            else
                ViewData["NxtVisibility"] = "visibility:hidden;";

            foreach (Seed sd in lstSeed)
            {
                sd.seedDistance = (int)objCmnMethods.distance(Convert.ToDouble(latSearch), Convert.ToDouble(lngSearch), Convert.ToDouble(sd.Location.localLat), Convert.ToDouble(sd.Location.localLong));
            }
            if (lstSeed.Count > 0)
                SessionStore.SetSessionValue(SessionStore.DiscoverSeed, lstSeed);
            ViewData["SeedList"] = lstSeed.OrderBy(x => x.seedDistance).ToList();

            ViewData["MarkerList"] = MarkerGenerator((IList<Seed>)ViewData["SeedList"]);

            //ListBox
            if (Session["SelectedCategory"] != null)
            {
                Session["SelectedCategory"] = null;
            }
            else
            {
                if (str != null)
                {
                    string myString = null;
                    for (int i = 0; i < str.Length; i++)
                    {
                        if (i == 0)
                        {
                            myString = str[i];

                        }
                        else
                        {
                            myString = myString + "," + str[i];
                        }
                    }
                    Session["SelectedCategory"] = myString;
                    ViewData["SelectedCategories"] = myString;
                }
            }
            //ListBox
            if (lstSeed.Count > 0)
            {
                CategoryAction objCat = new CategoryAction();
                IList<Category> categ = new List<Category>();
                Category c = null;
                foreach (Seed s in lstSeed)
                {
                    IList<Category> listCategory = s.Categories.ToList();
                    if (listCategory.Count > 0)
                    {
                        foreach (Category c1 in listCategory)
                        {
                            c = objCat.GetCategoryById(s.Categories.FirstOrDefault().id.ToString());
                            if (c != null)
                                categ.Add(c);
                        }
                    }
                }
                ViewData["SeedCategories"] = categ.Distinct().ToList();
            }

            return View();
        }
 /// <summary>
 /// Loads the albums for the Facebook User.
 /// </summary>
 public void LoadAlbums(Api fb, int userId)
 {
     FacebookApi = fb;
     UserId = userId;
     LoadAlbums();
 }
        /// <summary>
        /// Check if user has the proper permissions for this app
        /// </summary>
        public string CheckPermissions()
        {
            #if !SILVERLIGHT
            if (RequiredPermissions != null)
            {
                List<Enums.ExtendedPermissions> permissionsToApprove = new List<Enums.ExtendedPermissions>();
                string query = string.Format("select {0} from permissions where uid = {1}", PermissionsToString(RequiredPermissions), this.UserId); ;

                var fql = new Api().Initialize(this).Fql;

                var permission = fql.Query<permissions_response>(query);

                foreach (Enums.ExtendedPermissions p in this.RequiredPermissions)
                {
                    FieldInfo f = permission.permissions.GetType().GetField(p.ToString());
                    if (f != null)
                    {
                        bool hasPermission = (bool)f.GetValue(permission.permissions);
                        if (!hasPermission)
                        {
                            permissionsToApprove.Add(p);
                        }
                    }
                }

                if (permissionsToApprove.Count != 0)
                {
                    return PermissionsToString(permissionsToApprove);
                }
            }
            #endif
            return null;
        }
        private void LoadFromRequest()
        {
            if (string.IsNullOrEmpty(ApplicationKey) || string.IsNullOrEmpty(ApplicationSecret))
            {
                throw new Exception(
                    "Session must have application key and secret before logging in." + Environment.NewLine +
                    "To set them in your web.config, use something like the following:" + Environment.NewLine +
                    "<appSettings>" + Environment.NewLine +
                    "   <add key=\"ApiKey\" value =\"YOURApiKEY\"/>" + Environment.NewLine +
                    "   <add key=\"Secret\" value =\"YOURSECRET\"/>" + Environment.NewLine +
                    "</appSettings>\"");
            }

            if (HttpContext.Current.Response == null || HttpContext.Current.Request == null)
            {
                throw new Exception("Session must have both an HttpRequest object and an HttpResponse object to login.");
            }

            bool inProfileTab = HttpContext.Current.Request[QueryParameters.InProfileTab] == "1";
            string sessionKeyFromRequest = inProfileTab ? HttpContext.Current.Request[QueryParameters.ProfileSessionKey] : HttpContext.Current.Request[QueryParameters.SessionKey];
            string authToken = HttpContext.Current.Request[QueryParameters.AuthToken];
            CachedSessionInfo cachedSessionInfo = LoadCachedSession();

            if (!string.IsNullOrEmpty(sessionKeyFromRequest))
            {
                SetSessionProperties(
                    sessionKeyFromRequest,
                    long.Parse(inProfileTab ? HttpContext.Current.Request[QueryParameters.ProfileUser] : HttpContext.Current.Request[QueryParameters.User]),
                    DateHelper.ConvertUnixTimeToDateTime(long.Parse(HttpContext.Current.Request[QueryParameters.Expires])));
            }
            else if (HaveValidCachedSession(cachedSessionInfo, authToken, HttpContext.Current.Request[QueryParameters.ApiKey]))
            {
                SetSessionProperties(cachedSessionInfo.SessionKey, cachedSessionInfo.UserId, cachedSessionInfo.ExpiryTime);
            }
            else if (!string.IsNullOrEmpty(authToken))
            {
                session_info sessionInfo = new Api().Initialize(this).Auth.GetSession(authToken);
                SetSessionProperties(sessionInfo.session_key, sessionInfo.uid, DateHelper.ConvertUnixTimeToDateTime(sessionInfo.expires));
            }
        }
예제 #12
0
        private string ManageFacebook()
        {
            string FacebookUserAuthicatedCheck = "false";
            // Authenticated, created session and API object
            _connectSession = new ConnectSession(APPLICATION_KEY, SECRET_KEY);
            _connectSession.Logout();
            _connectSession.Login();

            //Check User Is Login in with Facebook
            if (_connectSession.IsConnected())
            {
                // Authenticated, create API instance

                _facebookAPI = new Api(_connectSession);
                user user = null;
                if (_facebookAPI != null)
                {
                    try
                    {
                        // Load user
                        user = _facebookAPI.Users.GetInfo();
                        string a = _facebookAPI.LogOffUrl;
                    }
                    catch (Exception ex)
                    {
                        return FacebookUserAuthicatedCheck;
                    }
                }

                if (user != null)
                {
                    long FacebookID = user.uid.Value;

                    FacebookUserAuthicatedCheck = FacebookAuthenticateUser(FacebookID);

                    return FacebookUserAuthicatedCheck;
                }
            }

            return FacebookUserAuthicatedCheck;
        }