How to open “Go to app” pop up on facebook page tab's checkbox click

瘦欲@ 提交于 2019-12-24 08:03:11

问题


Here is my facebook page

When a user click on a Fitbook Contest second tab then it will first force a user to like a page and then allow to use my application. But To access my app, First user needs to allow an appication then only my app will be accessed by user.

I am doing this coding in a c#.net. Here is my code.

TestFB.aspx.cs Code :

 public partial class TestFB : System.Web.UI.Page
    {
        private static string access_token = "";
        protected string form_url = "";

        public static string FacebookID = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetItemsList();

                if (string.IsNullOrEmpty(Convert.ToString(Session["access_token"])))
                {
                    string app_id = "139295982898884";
                    string app_secret = "b5d2a88b56898610d54da2af498e3220";
                    string post_login_url = "http://dev.fitbook.com.asp1-23.ord1-1.websitetestlink.com/v4/FitbookContest.aspx";
                    //string post_login_url = "http://localhost:4327/FitbookContest.aspx";
                    string scope = "publish_stream,manage_pages";

                    string code = HttpContext.Current.Request["code"] ?? "";

                    if (code == "")
                    {
                        string dialog_url = "http://www.facebook.com/dialog/oauth?" + "client_id=" + app_id + "&redirect_uri=" + HttpContext.Current.Server.UrlEncode(post_login_url) + "&scope=publish_stream&display=popup";
                        HttpContext.Current.Response.Redirect(dialog_url);
                        Response.Write(dialog_url);
                    }
                    else
                    {
                        Dictionary<string, string> tokens = new Dictionary<string, string>();

                        string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                            app_id, HttpContext.Current.Request.Url.AbsoluteUri, scope, HttpContext.Current.Request["code"].ToString(), app_secret);

                        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

                        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                        {
                            StreamReader reader = new StreamReader(response.GetResponseStream());

                            string vals = reader.ReadToEnd();

                            foreach (string token in vals.Split('&'))
                            {
                                //meh.aspx?token1=steve&token2=jake&...
                                tokens.Add(token.Substring(0, token.IndexOf("=")),
                                    token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                            }
                        }
                        access_token = tokens["access_token"];
                        Session["access_token"] = access_token;
                        GetProfilePic(code);
                    }
                    //Session["ProfileImage"] = imgProfilePicture;
                }
            }
        }

        private void GetProfilePic(string code)
        {
            string accesstoken = Convert.ToString(Session["access_token"]);
            var app = new FacebookClient(accesstoken);
            var me = (IDictionary<string, object>)app.Get("me");
            TestFB.FacebookID = (string)me["id"];
            string firstName = (string)me["first_name"];
            string lastName = (string)me["last_name"];
            string gender = (string)me["gender"];
            //Response.Write(me);

            string url = "http://graph.facebook.com/" + TestFB.FacebookID + "/picture";
            // Response.Write(url);
            //Image imgProfilePicture = new Image();
            //imgProfilePicture = (Image)HttpContext.Current.Session["ProfileImage"];
            imgProfilePicture.ImageUrl = url;
        }
}

It is working fine with localhost and my server from when i am accessing my page directly. But when i am integrating server path with "Facebook Page Tab", it is not open up an pop up and showing blank white screen instead. Here is a link for my page tab app . I am looking for something like this

Suggestions are welcomed. Thanks for any Help.

来源:https://stackoverflow.com/questions/14827155/how-to-open-go-to-app-pop-up-on-facebook-page-tabs-checkbox-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!