当前位置: 首页>>代码示例>>C#>>正文


C# FacebookClient.getLoginUrl方法代码示例

本文整理汇总了C#中Facebook.FacebookClient.getLoginUrl方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.getLoginUrl方法的具体用法?C# FacebookClient.getLoginUrl怎么用?C# FacebookClient.getLoginUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facebook.FacebookClient的用法示例。


在下文中一共展示了FacebookClient.getLoginUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            var config = new Dictionary<string, object>();

            //your application id and secret from https://developers.facebook.com/apps
            config.Add("appId", "3955...........");
            config.Add("secret", "4c1d099f9377b52eb...............");
            config.Add("fileUpload", true); //optional

            FacebookClient client = new FacebookClient(config);

            ulong facebookId = client.getUser();

            var loginPrms = new Dictionary<string, object>();

            string[] permissions = { "email", "friends_likes", "publish_stream" };

            //or you can use the helper classes FacebookUserDataPermissions, FacebookFriendDataPermissions, FacebookExtendedPermissions for autocomplete in visual studio.
            //string[] permissions = {FacebookUserDataPermissions.email, FacebookFriendDataPermissions.friends_likes, FacebookExtendedPermissions.publish_stream};
            loginPrms.Add("scope", permissions); //optional

            //your application url
            loginPrms.Add("redirect_uri", new Uri("http://apps.facebook.com/yourappnamespace"));

            //you can save this random string to a session variable check at the beginning for csrf protection.
            loginPrms.Add("state", "randomstring"); //optional

            //the default value is "page" you can change this to "popup".
            loginPrms.Add("display", "page"); //optional

            var logoutPrms = new Dictionary<string, object>();

            //optional logout redirect uri.
            logoutPrms.Add("next", "http://apps.facebook.com/yourappnamespace");

            //the user is not added the application we redirect it to our permission screen.
            if (facebookId == 0)
            {
                Response.Write("<script>top.location.href='" + client.getLoginUrl(loginPrms) + "';</script>");
            }
            else
            {
                //we get the short lived access token and exchange it for 60 days extension.
                client.setExtendedAccessToken();

                //all methods and their return values for testing

                // getAccessToken first retrieves the application access token, if exists this value is changed to user access token for our application.
                Response.Write("php sdk equivalent $facebook->getAccessToken();" + client.getAccessToken() + "<br/>");

                //gets our app secret from the config value.
                Response.Write("php sdk equivalent $facebook->getApiSecret();" + client.getApiSecret() + "<br/>");

                //gets our app id from the config value.
                Response.Write("php sdk equivalent $facebook->getAppId();" + client.getAppId() + "<br/>");

                //gets our login url with permissions we defined in loginPrms variable. getLoginStatusUrl is basically a wrapper for getLoginUrl.
                Response.Write("php sdk equivalent $facebook->getLoginStatusUrl();" + client.getLoginStatusUrl(loginPrms) + "<br/>");
                Response.Write("php sdk equivalent $facebook->getLoginUrl();" + client.getLoginUrl(loginPrms) + "<br/>");

                //retrieves the signed_request post value from facebook in our application and retrieves a Dictionary<string, object>.
                //for more info please refer to  http://developers.facebook.com/docs/reference/login/signed-request/

                foreach (KeyValuePair<string, object> kvp in client.getSignedRequest())
                {
                    //user is json object
                    if (kvp.Key == "user")
                    {
                        foreach (KeyValuePair<string, object> fields in client.getSignedRequest()["user"] as Dictionary<string, object>)
                        {
                            //age in user is also a json object
                            if(fields.Key == "age")
                            {
                                foreach (KeyValuePair<string, object> field in fields.Value as Dictionary<string, object>)
                                {
                                    Response.Write("php sdk equivalent $facebook->getSignedRequest();" + field.Key + " - " + field.Value + "<br/>");
                                }
                            }
                            else
                            {
                                Response.Write("php sdk equivalent $facebook->getSignedRequest();" + fields.Key + " - " + fields.Value + "<br/>");
                            }
                        }
                    }
                    //page is json object
                    if (kvp.Key == "page")
                    {
                        foreach (KeyValuePair<string, object> fields in client.getSignedRequest()["page"] as Dictionary<string, object>)
                        {
                            Response.Write("php sdk equivalent $facebook->getSignedRequest();" + fields.Key + " - " + fields.Value + "<br/>");
                        }
                    }
                    else
                    {
                        Response.Write("php sdk equivalent $facebook->getSignedRequest();" + kvp.Key + " - " + kvp.Value + "<br/>");
                    }

                }

                //retrieves the signed user facebook id as ulong
//.........这里部分代码省略.........
开发者ID:barans,项目名称:FacebookCsharpSdk,代码行数:101,代码来源:Default.aspx.cs


注:本文中的Facebook.FacebookClient.getLoginUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。