Facebook.FacebookOAuthClient.GetLoginUrl C# (CSharp) Method

GetLoginUrl() public method

Gets the login uri.
http://developers.facebook.com/docs/reference/dialogs/oauth Parameters that can be used: client_id : Your application's identifier. This is called client_id instead of app_id for this particular method to be compliant with the OAuth 2.0 specification. Required, but automatically specified by most SDKs. redirect_uri : The URL to redirect to after the user clicks a button on the dialog. Required, but automatically specified by most SDKs. scope : Optional. A comma-delimited list of permissions. state : Optional. An opaque string used to maintain application state between the request and callback. When Facebook redirects the user back to your redirect_uri, this value will be included unchanged in the response. response_type : Optional, default is token. The requested response: an access token (token), an authorization code (code), or both (code_and_token). display : The display mode in which to render the dialog. The default is page on the www subdomain and wap on the m subdomain. This is automatically specified by most SDKs. (For WP7 builds it is set to touch.)
public GetLoginUrl ( object>.IDictionary parameters ) : Uri
parameters object>.IDictionary /// The parameters. ///
return System.Uri
        public Uri GetLoginUrl(IDictionary<string, object> parameters)
        {
            Contract.Ensures(Contract.Result<Uri>() != null);

            var defaultParameters = new Dictionary<string, object>();
            defaultParameters["client_id"] = AppId;
            defaultParameters["redirect_uri"] = RedirectUri ?? new Uri("http://www.facebook.com/connect/login_success.html");
#if WINDOWS_PHONE
            defaultParameters["display"] = "touch";
#endif
            var mergedParameters = FacebookUtils.Merge(defaultParameters, parameters);

            // check if client_id and redirect_uri is not null or empty.
            if (mergedParameters["client_id"] == null || string.IsNullOrEmpty(mergedParameters["client_id"].ToString()))
            {
                throw new ArgumentException("client_id required.");
            }

            if (mergedParameters["redirect_uri"] == null || string.IsNullOrEmpty(mergedParameters["redirect_uri"].ToString()))
            {
                throw new ArgumentException("redirect_uri required.");
            }

            // seems like if we don't do this and rather pass the original uri object,
            // it seems to have http://localhost:80/csharpsamples instead of
            // http://localhost/csharpsamples
            // notice the port number, that shouldn't be there.
            // this seems to happen for iis hosted apps.
            mergedParameters["redirect_uri"] = mergedParameters["redirect_uri"].ToString();

            var url = "http://www.facebook.com/dialog/oauth/?" + FacebookUtils.ToJsonQueryString(mergedParameters);

            return new Uri(url);
        }

Same methods

FacebookOAuthClient::GetLoginUrl ( ) : Uri
FacebookOAuthClient::GetLoginUrl ( string appId, Uri redirectUri ) : Uri
FacebookOAuthClient::GetLoginUrl ( string appId, Uri redirectUri, string extendedPermissions ) : Uri
FacebookOAuthClient::GetLoginUrl ( string appId, Uri redirectUri, string extendedPermissions, object>.IDictionary loginParameters ) : Uri
FacebookOAuthClient::GetLoginUrl ( string appId, Uri redirectUri, string extendedPermissions, bool logout, object>.IDictionary loginParameters ) : Uri

Usage Example

        /// <summary>
        /// Get FacebookOAuthClient.
        /// </summary>
        void MainPage_Loaded()
        {
            using (DbStorage fbdb = new DbStorage(strConnectionString))
            {
                IQueryable<Db> fbQuery = from db in fbdb.user select db;
                Db ac = fbQuery.FirstOrDefault();
                if(ac == null){
                    string appId = "YOUR FACEBOOK APP ID";
                    string[] extendedPermissions = new[] { "publish_stream"};

                    var oauth = new FacebookOAuthClient { AppId = appId };
                    var parameters = new Dictionary<string, object>
                            {
                               { "response_type", "token" },
                                { "display", "touch" }
                            };
                    if (extendedPermissions != null && extendedPermissions.Length > 0)
                    {
                        var scope = new StringBuilder();
                        scope.Append(string.Join(",", extendedPermissions));
                        parameters["scope"] = scope.ToString();
                    }
                    var loginUrl = oauth.GetLoginUrl(parameters);
                    //Add webBrowser to the contentPanel
                    _webBrowser.Navigate(loginUrl);
                    ContentPanel.Children.Add(_webBrowser);
                    _webBrowser.Navigated += webBrowser_Navigated;
                    //Open the facebook login page into the browser
           
            }
        }
        }
All Usage Examples Of Facebook.FacebookOAuthClient::GetLoginUrl