public DataSet ExecuteQuery(string queryCommand, fbuser fbuser) { string errorInfo = String.Empty; DataSet queryResults = null; try { WebClient wc = new WebClient(); wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters //string result = wc.DownloadString("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=36922302396"); string result = wc.DownloadString("https://api.facebook.com/method/fql.query?query=" + queryCommand + "&access_token=" + fbuser.AccessToken); /*string xmlDataReturned = API.fql.query(queryCommand);*/ queryResults = new DataSet(); System.IO.StringReader xmlReader = new System.IO.StringReader(result); queryResults.ReadXml(xmlReader); return queryResults; } catch (Exception ex_exec_query) { errorInfo = "Failed to exec [" + queryCommand + "]:" + ex_exec_query.Message; return queryResults; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { fbuser = sitetemp.getfbuser(); if ((fbuser.UID == 121100861) || (fbuser.UID == 1566199117)) { //Lorne or Sarah DataSet dstemp = BlueIkons_DB.SPs.ViewCharity(0).GetDataSet(); txtemail.Text = dstemp.Tables[0].Rows[0]["Charity_Email"].ToString(); txtname.Text = dstemp.Tables[0].Rows[0]["Charity_Name"].ToString(); txtdescription.Text = dstemp.Tables[0].Rows[0]["Charity_Description"].ToString(); } else { //redirect person btnsave.Enabled = false; lblerror.Text = "You are not authorized to be here"; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Form["__EVENTTARGET"] == "btnpaypal") { btnpaypal(); } if ((Request.QueryString["fbid"] != null) && (Request.QueryString["fbid"] != "")) { fbuser = sitetemp.Getfbuser(Convert.ToInt64(Request.QueryString["fbid"].ToString())); } else if (hdfbid.Value != "0") { fbuser = sitetemp.Getfbuser(Convert.ToInt64(hdfbid.Value)); } else { fbuser = sitetemp.getfbuser(); } hdfbid.Value = fbuser.UID.ToString(); if (!IsPostBack) { //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert('standardone');", ""); //RadAjaxPanel1.ResponseScripts.Add("alert('hello');"); updatefriendslist(); int pendinggiftamount = sitetemp.checkifhavegiftamount(fbuser.UID); if (pendinggiftamount > 0) { hyppendinggift.Text = "You have " + pendinggiftamount.ToString() + " pending gifts, click here to redeem"; hyppendinggift.NavigateUrl = "getgift.aspx?fbid=" + fbuser.UID.ToString(); } } /* Setfbid(); } else { Response.Redirect("http://www.facebook.com/dialog/oauth?client_id=" + ConfigurationSettings.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&scope=email,publish_stream"); } */ }
protected void Page_Load(object sender, EventArgs e) { fbuser = siteTemp.getfbuser(); if (!IsPostBack) { //populate charities info DataSet dstemp = BlueIkons_DB.SPs.ViewFbidpendinggifts(fbuser.UID).GetDataSet(); if (dstemp.Tables[0].Rows.Count > 0) { int giftkey = Convert.ToInt32(dstemp.Tables[0].Rows[0]["Gift_Key"]); dstemp = BlueIkons_DB.SPs.ViewCharity(giftkey).GetDataSet(); lblcharityname.Text = dstemp.Tables[0].Rows[0]["Charity_Name"].ToString(); lblcharitydescription.Text = dstemp.Tables[0].Rows[0]["Charity_Description"].ToString(); hdcharityemail.Value = dstemp.Tables[0].Rows[0]["Charity_Email"].ToString(); gift giftinfo = siteTemp.GetGiftInfo(giftkey); lblamount.Text = string.Format("{0:C}", giftinfo.amount); lblhumanid.Text = giftkey.ToString(); lblgiftid.Text = giftinfo.Gift_Key.ToString(); lblgiftamount.Text = string.Format("{0:C}", giftinfo.amount); lblinfo.Text = giftkey.ToString(); //check if gift is still good if (siteTemp.Gifthasbeenreceived(giftkey)) { Response.Redirect("givegift.aspx?fbid=" + fbuser.UID.ToString() + "&alert=1"); } PayPal pp = new PayPal(); Transactions txinfo = siteTemp.Gettx(giftinfo.txkey); if (!pp.PreapprovalActive(txinfo.pakey, Live_Trial,giftinfo.txkey)) { //Is not active Response.Redirect("givegift.aspx?fbid=" + fbuser.UID.ToString() + "&alert=2"); } } } if (Request.Form["__EVENTTARGET"] == "btnpf") { btnpf(); } if (Request.Form["__EVENTTARGET"] == "btncollect") { btnpf(); } }
public string SetPreapproval(fbuser fbuser, bool Live_Trial, int Tx_Key, decimal amount) { string strReturn = ""; PreapprovalRequest preapprovalRequest = null; BaseAPIProfile profile2 = new BaseAPIProfile(); profile2.APIProfileType = ProfileType.ThreeToken; if (Live_Trial)//true = Live , false = trial { profile2.Environment = ConfigurationManager.AppSettings.Get("Live_Environment").ToString(); profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID_Live").ToString(); profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername_Live").ToString(); profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword_Live").ToString(); profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature_Live").ToString(); } else { profile2.Environment = ConfigurationManager.AppSettings.Get("Trial_Environment").ToString(); profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID").ToString(); profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername").ToString(); profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword").ToString(); profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature").ToString(); } profile2.RequestDataformat = "SOAP11"; profile2.ResponseDataformat = "SOAP11"; profile2.IsTrustAllCertificates = Convert.ToBoolean(ConfigurationManager.AppSettings["TrustAll"]); try { decimal amountfee1 = (amount * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3); decimal amountblueikon = (amount * Convert.ToDecimal(0.1)); decimal amountfee2 = (amountblueikon * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3); amount = amount + amountblueikon + amountfee1 + amountfee2; amount = decimal.Round(amount, 2); string url = ConfigurationManager.AppSettings.Get("App_URL").ToString() ; string returnURL = "http://www.blueikons.com/Order_Confirmation.aspx?Tx_key=" + Tx_Key.ToString(); string cancelURL = url; preapprovalRequest = new PreapprovalRequest(); preapprovalRequest.cancelUrl = cancelURL; preapprovalRequest.returnUrl = returnURL; //preapprovalRequest.senderEmail = senderEmail.Value; preapprovalRequest.requestEnvelope = new RequestEnvelope(); preapprovalRequest.requestEnvelope.errorLanguage = "en-US"; preapprovalRequest.maxNumberOfPayments = 2; preapprovalRequest.maxTotalAmountOfAllPayments = amount; preapprovalRequest.maxTotalAmountOfAllPaymentsSpecified = true; preapprovalRequest.currencyCode = "USD"; preapprovalRequest.startingDate = DateTime.Today; preapprovalRequest.endingDate = DateTime.Today.AddMonths(1); preapprovalRequest.endingDateSpecified = true; preapprovalRequest.clientDetails = new ClientDetailsType(); //preapprovalRequest.clientDetails = ClientInfoUtil.getMyAppDetails(); preapprovalRequest.memo = "BlueIkons"; preapprovalRequest.maxNumberOfPayments = 2; preapprovalRequest.displayMaxTotalAmount = true; preapprovalRequest.displayMaxTotalAmountSpecified = true; preapprovalRequest.feesPayer = "SENDER"; AdapativePayments ap = new AdapativePayments(); ap.APIProfile = profile2; PreapprovalResponse PResponse = ap.preapproval(preapprovalRequest); if (ap.isSuccess.ToUpper() == "FAILURE") { //HttpContext.Current.Session[Constants.SessionConstants.FAULT] = ap.LastError; //HttpContext.Current.Response.Redirect("APIError.aspx", false); } else { // Session[Constants.SessionConstants.PREAPPROVALKEY] = PResponse.preapprovalKey; //this.Response.Redirect(ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-preapproval&preapprovalkey=" + PResponse.preapprovalKey, false); BlueIkons_DB.SPs.UpdateTransactionPakey(Tx_Key, PResponse.preapprovalKey).Execute(); if (Live_Trial)//true = Live , false = trial { //HttpContext.Current.Response.Redirect("https://paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + PResponse.preapprovalKey, false); } else{ //HttpContext.Current.Response.Redirect("https://www.sandbox.paypal.com/webscr?cmd=" + "_ap-payment&paykey=" + PResponse.preapprovalKey, false); } strReturn = PResponse.preapprovalKey; } } catch (FATALException FATALEx) { // Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx; // this.Response.Redirect(Constants.ASPXPages.APIERROR + "?" + Constants.QueryStringConstants.TYPE + "=FATAL", false); } catch (Exception ex) { //FATALException FATALEx = new FATALException("Error occurred in PreApproval Page.", ex); //Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx; //this.Response.Redirect("APIError.aspx?type=FATAL", false); } return strReturn; }
private void updateinvite(fbuser localfbuser) { //set fbid as receiver of gift int giftkey = 0; if (HttpContext.Current.Request.QueryString["invite"] != null) { giftkey = Convert.ToInt32(HttpContext.Current.Request.QueryString["invite"]); } else if (HttpContext.Current.Request.QueryString["invite"] != null) { giftkey = Convert.ToInt32(HttpContext.Current.Request.QueryString["invite"]); } //check if gift is still good if (Gifthasbeenreceived(giftkey)) { HttpContext.Current.Response.Redirect("givegift.aspx?fbid=" + localfbuser.UID.ToString() + "&alert=1"); } PayPal pp = new PayPal(); try { gift giftinfo = GetGiftInfo(giftkey); Transactions txinfo = Gettx(giftinfo.txkey); if (!pp.PreapprovalActive(txinfo.pakey, Live_Trial, giftinfo.txkey)) { //Is not active HttpContext.Current.Response.Redirect("givegift.aspx?fbid=" + localfbuser.UID.ToString() + "&alert=2"); } if (!Gifthasreceiver(giftkey)) { BlueIkons_DB.SPs.UpdateGiftReceiver(giftkey, localfbuser.UID).Execute(); } HttpContext.Current.Session["invite"] = null; } catch { } }
/* private fbuser Setfbid() { string oauth = ""; oauth = HttpContext.Current.Request.QueryString["code"].ToString(); //oauth = oauth.Substring(0, oauth.IndexOf("|")); fbuser fbuser = new fbuser(); //oauth = oauth.Substring(0, oauth.IndexOf("|")); WebClient wc = new WebClient(); wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters //string result = wc.DownloadString("https://graph.facebook.com/oauth/access_token?response_type=token&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&code=" + oauth); string strsend = "https://graph.facebook.com/oauth/access_token?client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&client_secret=" + ConfigurationManager.AppSettings.Get("Secret").ToString() + "&code=" + oauth; var url = "https://graph.facebook.com/oauth/authorize?client_id=" + ConfigurationSettings.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + ConfigurationSettings.AppSettings.Get("App_URL").ToString() + "default.aspx&scope=" + strrequiredAppPermissions; string result = wc.DownloadString(url); string accesstoken = result.Replace("access_token=", ""); int endofaccesstoken = accesstoken.IndexOf("&expire"); accesstoken = accesstoken.Substring(0, endofaccesstoken); //Get user id wc.Encoding = System.Text.Encoding.UTF8; //This is if you have non english characters string result2 = wc.DownloadString("https://graph.facebook.com/me?access_token=" + accesstoken); try { JObject o = JObject.Parse(result2); string fbid = (string)o["id"]; string email = ""; string firstname = ""; string lastname = ""; if (o["email"] != null) { email = (string)o["email"]; } if (o["first_name"] != null) { firstname = (string)o["first_name"]; } if (o["last_name"] != null) { lastname = (string)o["last_name"]; } bool isnewuser = false; BlueIkons_DB.SPs.UpdateFBUser(Convert.ToInt64(fbid), firstname, lastname, email, accesstoken).Execute(); fbuser.UID = Convert.ToInt64(fbid); fbuser.Email = email; fbuser.Firstname = firstname; fbuser.Lastname = lastname; fbuser.AccessToken = accesstoken; } catch { } return fbuser; }*/ protected fbuser PopulatefbuserGraph() { CanvasAuthorizer authorizer; fbuser localfbuser = new fbuser(); FacebookApp fbApp = new FacebookApp(); authorizer = new CanvasAuthorizer(); authorizer.Permissions = requiredAppPermissions; //if ((authorizer.Session != null) || ((HttpContext.Current.Request.QueryString["code"] != null) && (HttpContext.Current.Request.QueryString["code"] != ""))) if (authorizer.Session != null) { //ShowFacebookContent(); JsonObject myInfo = (JsonObject)fbApp.Get("me"); localfbuser.UID = Convert.ToInt64(myInfo["id"].ToString()); localfbuser.AccessToken = fbApp.AccessToken; localfbuser.SessionKey = fbApp.Session.Signature; localfbuser.Firstname = myInfo["first_name"].ToString(); localfbuser.Lastname = myInfo["last_name"].ToString(); localfbuser.Fullname = localfbuser.Firstname + " " + localfbuser.Lastname; localfbuser.Email = getfbappemail(myInfo); //HttpContext.Current.Session["fbuser"] = fbuser; BlueIkons_DB.SPs.UpdateFBUser(localfbuser.UID, localfbuser.Firstname, localfbuser.Lastname, localfbuser.Email, localfbuser.AccessToken).Execute(); if ((HttpContext.Current.Session["invite"] != null) || (HttpContext.Current.Request.QueryString["invite"] != null)) { updateinvite(localfbuser); } //Eventomatic_DB.SPs.UpdateResource(fbuser.UID, fbuser.Firstname, fbuser.Lastname, "", HttpContext.Current.Request.UserHostAddress, GetCurrentPageName(), 0, 0, fbuser.SessionKey, fbuser.AccessToken, 0).Execute(); } else if ((HttpContext.Current.Request.QueryString["fbid"] != null) && (HttpContext.Current.Request.QueryString["fbid"] != "")) { localfbuser = Getfbuser(Convert.ToInt64(HttpContext.Current.Request.QueryString["fbid"].ToString())); if (HttpContext.Current.Request.QueryString["invite"] != null) { updateinvite(localfbuser); } //HttpContext.Current.Session["fbuser"] = fbuser; } else { if (HttpContext.Current.Request.QueryString["invite"] != null) { //remember invitekey HttpContext.Current.Session["invite"] = HttpContext.Current.Request.QueryString["invite"].ToString(); } var pageName = Path.GetFileName(HttpContext.Current.Request.PhysicalPath); var urlSB = new StringBuilder(); urlSB.Append("https://graph.facebook.com/oauth/authorize?client_id="); urlSB.Append(ConfigurationManager.AppSettings["fbAppID"]); urlSB.Append("&redirect_uri="); urlSB.Append(ConfigurationManager.AppSettings["App_URL"]); urlSB.Append(pageName); urlSB.Append("&scope="); urlSB.Append(strrequiredAppPermissions); //var url = authorizer.ge auth.GetLoginUrl(new HttpRequestWrapper(Request)); Uri newuri = new Uri(urlSB.ToString()); var content = CanvasUrlBuilder.GetCanvasRedirectHtml(newuri); HttpContext.Current.Response.ContentType = "text/html"; HttpContext.Current.Response.Write(content); HttpContext.Current.Response.End(); } return localfbuser; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { fbuser fbuser = new fbuser(); if ((HttpContext.Current.Request.QueryString["fbid"] != null) && (HttpContext.Current.Request.QueryString["fbid"] != "")) { fbuser = Getfbuser(Convert.ToInt64(HttpContext.Current.Request.QueryString["fbid"].ToString())); } else { fbuser = getfbuser(); } if (fbuser != null) { string strcurrentpage = Body.Page.GetType().FullName; /* if (((!strcurrentpage.ToLower().Contains("getgift")) && (checkifhavegift(fbuser.UID)))) { Response.Redirect("getgift.aspx?fbid="+fbuser.UID.ToString()); //hdredirect.Value = "getgift.aspx"; } else if (strcurrentpage.ToLower().Contains("default")) { Response.Redirect("givegift.aspx?fbid="+fbuser.UID.ToString()); //hdredirect.Value = "givegift.aspx"; } */ if (strcurrentpage.ToLower().Contains("default")) { Response.Redirect("givegift.aspx?fbid=" + fbuser.UID.ToString()); } if (HttpContext.Current.Request.QueryString["alert"] != null){ string thealert = HttpContext.Current.Request.QueryString["alert"].ToString(); if (hdpopup != null){ switch (thealert) { case "1": hdpopup.Value = "You already accepted this gift."; break; case "2": hdpopup.Value = "Your gift has already expired or cancelled."; break; } } } } lbluser.Text = fbuser.Firstname + " " + fbuser.Lastname; } }
public DataTable getFriendslist(fbuser fbuser) { DataTable dtFriendsList = new DataTable("FBFriends"); DataColumn cltemp; DataColumn cltemp2; DataRow rtemp; cltemp = new DataColumn(); cltemp.DataType = System.Type.GetType("System.String"); cltemp.ColumnName = "fbid"; cltemp.ReadOnly = false; cltemp.Unique = true; dtFriendsList.Columns.Add(cltemp); cltemp2 = new DataColumn(); cltemp2.DataType = System.Type.GetType("System.String"); cltemp2.ColumnName = "Name"; cltemp2.ReadOnly = false; cltemp2.Unique = true; dtFriendsList.Columns.Add(cltemp2); Hashtable fbht = new Hashtable(); ListItem litemp = new ListItem(); //System.Collections.Generic.IList<facebook.Schema.user> friends = Master.API.friends.getUserObjects(); string fbid = fbuser.UID.ToString(); DataSet dstemp = ExecuteQuery("SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 ='" + fbid + "')", fbuser); //foreach (facebook.Schema.user friend in friends) foreach (DataRow r in dstemp.Tables[1].Rows) { //ListItem li = new ListItem(friend.name, friend.uid.ToString()); //lstFacebookFriends.Items.Add(li); litemp.Value = r["uid"].ToString(); //friend.uid.ToString(); litemp.Text = r["name"].ToString();//friend.name.ToString(); if ((!fbht.ContainsValue(r["name"].ToString().ToUpper()))) { rtemp = dtFriendsList.NewRow(); rtemp[0] = r["uid"].ToString(); rtemp[1] = r["name"].ToString(); dtFriendsList.Rows.Add(rtemp); fbht.Add(r["uid"].ToString(), r["name"].ToString().ToUpper()); } } dtFriendsList.DefaultView.Sort = "Name asc"; return dtFriendsList; }
public fbuser Getfbuser(Int64 intfbuser) { fbuser fbuser = new fbuser(); fbuser.UID = intfbuser; DataSet dstemp = BlueIkons_DB.SPs.ViewFBUser(intfbuser).GetDataSet(); if (dstemp.Tables[0].Rows[0]["first_name"] != DBNull.Value) { fbuser.Firstname = dstemp.Tables[0].Rows[0]["first_name"].ToString(); } if (dstemp.Tables[0].Rows[0]["last_name"] != DBNull.Value) { fbuser.Lastname = dstemp.Tables[0].Rows[0]["last_name"].ToString(); } if (dstemp.Tables[0].Rows[0]["fbemail"] != DBNull.Value) { fbuser.Email = dstemp.Tables[0].Rows[0]["fbemail"].ToString(); } if (dstemp.Tables[0].Rows[0]["paypalemail"] != DBNull.Value) { fbuser.paypalemail = dstemp.Tables[0].Rows[0]["paypalemail"].ToString(); } if (dstemp.Tables[0].Rows[0]["Access_Token"] != DBNull.Value) { fbuser.AccessToken = dstemp.Tables[0].Rows[0]["Access_Token"].ToString(); } return fbuser; }
public fbuser getfbuser() { fbuser fbuser = new fbuser(); if (HttpContext.Current.Session["fbuser"] == null) //No authorization or fbuid { fbuser = PopulatefbuserGraph(); /* if ((HttpContext.Current.Request.QueryString["code"] != null) && (HttpContext.Current.Request.QueryString["code"] != "")) { fbuser = Setfbid(); HttpContext.Current.Session["fbuser"] = fbuser; } else { PopulatefbuserGraph(); //string strredirecturl = "http://www.facebook.com/dialog/oauth?client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&scope=email,publish_stream"; //hdredirect.Value = strredirecturl; //Response.Redirect("http://www.facebook.com/dialog/oauth?client_id=" + ConfigurationManager.AppSettings.Get("fbAppID").ToString() + "&redirect_uri=" + thereturnpage + "&scope=email,publish_stream"); } */ } //fbuser = (fbuser)HttpContext.Current.Session["fbuser"]; return fbuser; }