My connection code is as follows:
String appId = Facebook.FacebookApplication.Current.AppId;
var oauth = new FacebookOAuthClient { AppId = appId };
var parameters = new Dictionary<string, object>
{
{ "response_type", "code" },
{ "display", "popup" },
{ "scope", "email" }
};
var loginUrl = oauth.GetLoginUrl(parameters);
Response.Redirect(loginUrl);
I am getting the error: cannot convert ‘from System.Uri’ to ‘string’ on the last line. Apparently, the GetLoginUrl method returns a type Uri and Redirect requires a string. Is there another way to redirect to a type – Uri?
The example provided by codeplex is “webBrowser.Navigate(loginUrl);” but I am not using the webBrowser control. Should I be? Or is there another way?
I found one way to solve this.
Replace the last two lines:
var loginUrl = oauth.GetLoginUrl(parameters);
Response.Redirect(loginUrl);
With
var loginUrl = HttpUtility.HtmlEncode(oauth.GetLoginUrl(parameters));
Response.Redirect(HttpUtility.HtmlDecode(loginUrl));
Converting to HTML and back solves the problem. Note that if you leave the loginUrl HtmlEncoded, Facebook will return an error.
See this:
http://facebooksdk.codeplex.com/workitem/5859
Basically, use this: