我在登录后使用以下代码,该代码适用于5.4.1,但现在它没有按预期工作。
FacebookOAuthResult pResult;
if (m_pClient.TryParseOAuthCallbackUrl(e.Uri, out pResult))
{
if (pResult.IsSuccess)
{
//handle if success
}
else
{
//handle if failed
}
}
我将FacebookOAuthClient迁移到了FacebookClient,在迁移完所有内容之后,这不起作用。
我的登录代码如下。我尝试了旧方法和新方法,但两者都不起作用。评论部分是我的遗留代码,适用于5.4你能帮我看看我做错了吗?
//Dictionary<string, object> pParameters = new Dictionary<string, object>
//{
// {"response_type", "token"},
// {"display", "touch"},
//};
//if ((extendedPermissions != null) && (extendedPermissions.Length > 0))
//{
// StringBuilder pScope = new StringBuilder();
// pScope.Append(string.Join(",", extendedPermissions));
// pParameters["scope"] = pScope.ToString();
//}
这是为v6添加的代码
Uri pLoginUrl = m_pClient.GetLoginUrl(new { response_type = "token", display = "touch", scope = "publish_stream, offline_access", next = "https://www.facebook.com/connect/login_success.html" }); //also tried redirect_uri=""
m_pBrowser.Visibility = System.Windows.Visibility.Visible;
m_pBrowser.Navigate(pLoginUrl);
答案 0 :(得分:2)
我建议您查看https://github.com/facebook-csharp-sdk/facebook-winforms-sample
处的winforms示例 private Uri GenerateLoginUrl(string appId, string extendedPermissions)
{
dynamic parameters = new ExpandoObject();
parameters.client_id = appId;
parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
// The requested response: an access token (token), an authorization code (code), or both (code token).
parameters.response_type = "token";
// list of additional display modes can be found at http://developers.facebook.com/docs/reference/dialogs/#display
parameters.display = "popup";
// add the 'scope' parameter only if we have extendedPermissions.
if (!string.IsNullOrWhiteSpace(extendedPermissions))
parameters.scope = extendedPermissions;
var fb = new FacebookClient();
// when the Form is loaded navigate to the login url.
return fb.GetLoginUrl(parameters);
}