public GetLoginUrl ( object>.IDictionary |
||
parameters | object>.IDictionary | /// The parameters. /// |
return |
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);
}
FacebookOAuthClient::GetLoginUrl ( ) : |
|
FacebookOAuthClient::GetLoginUrl ( string appId, |
|
FacebookOAuthClient::GetLoginUrl ( string appId, |
|
FacebookOAuthClient::GetLoginUrl ( string appId, |
|
FacebookOAuthClient::GetLoginUrl ( string appId, |
/// <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 } } }