public string CallPageTabs(string PageID) { //now we have page_id, redirect user to PAGE URL string PageName = string.Empty; //use FQL to get page name etc StringBuilder oSBPgaeCaller = new StringBuilder(); oSBPgaeCaller.Append("https://api.facebook.com/method/fql.query?"); oSBPgaeCaller.Append("query=SELECT name FROM page WHERE page_id = " + PageID); //oSBPgaeCaller.Append("&access_token=" + Session["user_access_token"].ToString()); oSBPgaeCaller.Append("&format=JSON"); FaceBook objFB = new FaceBook(); //Parse json to get MXDBAppUser string _sUserInfoJson = objFB.CallWebRequest("GET", oSBPgaeCaller.ToString(), string.Empty); object[] oUserLocationDataRow = new object[5]; //Convert Json to JsonDictionary <of String, object> System.Web.Script.Serialization.JavaScriptSerializer _oJavaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); object _oJSONObject = _oJavaScriptSerializer.DeserializeObject(_sUserInfoJson); int i = 0; for (i = 0; i <= ((object[])_oJSONObject).Length - 1; i++) { Dictionary<string, object> _ojsonUserDetails = (Dictionary<string, object>)((object[])_oJSONObject)[i]; foreach (KeyValuePair<string, object> _oKeyjsonUserDetailsItem in _ojsonUserDetails) { switch (_oKeyjsonUserDetailsItem.Key) { case "name": //set Email PageName = Convert.ToString(_oKeyjsonUserDetailsItem.Value); break; } } } return PageName; }
protected void btnPageSelect_Click(object sender, EventArgs e) { try { DataTable dtNewPages = new DataTable(); DataColumn[] dcPage = new DataColumn[3]; dcPage[0] = new DataColumn("pid", System.Type.GetType("System.String")); dtNewPages.Columns.Add(dcPage[0]); dcPage[1] = new DataColumn("pname", System.Type.GetType("System.String")); dtNewPages.Columns.Add(dcPage[1]); dcPage[2] = new DataColumn("pacctoken", System.Type.GetType("System.String")); dtNewPages.Columns.Add(dcPage[2]); dtNewPages = (DataTable)(Cache["PageDetails"]); DataView dv; dv = new DataView((DataTable)(Cache["PageDetails"])); dv.RowFilter = "pname= '" + ddlPageSelect.SelectedItem.ToString() + "'"; //fetch the custom tab name FacebookBizProcess fbBiz = new FacebookBizProcess(); string custTabName = fbBiz.GetCustomTabName(SessionData.Config.AppID); StringBuilder _sbPostToWallPostData = new StringBuilder(); _sbPostToWallPostData.Append("custom_name=" + custTabName); string pagetab = "https://graph.facebook.com/" + dv[0]["pid"].ToString().Replace("\"", "") + "/tabs?method=POST&app_id=" + SessionData.Config.AppID + "&access_token=" + ddlPageSelect.SelectedValue.ToString().Replace("\"", ""); FaceBook fabo = new FaceBook(); fabo.CallWebRequest("POST", pagetab, _sbPostToWallPostData.ToString()); //generate URL for page tab //string pageName = CallPageTabs(dv[0]["pid"].ToString()); StringBuilder oSBAppPath = new StringBuilder(); oSBAppPath.Append("https://www.facebook.com/pages/"); oSBAppPath.Append(ddlPageSelect.SelectedItem.ToString() + "/"); oSBAppPath.Append(dv[0]["pid"].ToString() + "/"); oSBAppPath.Append("?sk=app_" + SessionData.Config.AppID); lblResult.Text = "Campaign uploaded. Click"; if (SessionData.UserAction.TaskComplete.Equals("M")) { lblInformation.Text = "Your Microsite has been processed ! Please find the details in your Email inbox."; } else if (SessionData.UserAction.TaskComplete.Equals("Y")) { lblInformation.Text = "Your Microsite has been processed ! Please find the details in your Email inbox."; } else { lblInformation.Text = string.Empty; } fbBiz.UpdateAppPagePath(oSBAppPath.ToString(), SessionData.Config.AppID, dv[0]["pid"].ToString()); linkToCamp.HRef = oSBAppPath.ToString(); tblPageSelect.Visible = false; tblResult.Visible = true; if (bEnableTwitter == true) { tblTweet.Visible = true; } //Response.Redirect("CanvasArea.aspx?CDID=" + SessionData.Customer.CustomerID+"&pageSelected=T&TID=0",true); } catch (Exception ex) { CommonUtility commUtil = new CommonUtility(); commUtil.SendErrorMail(ex.Message, ex.StackTrace, System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), SessionData.Customer.CustomerID); } }