在这里,我使用 facebook 生成的用户 ID 代替 appid 。我在这里正确吗?因为我想在 Windows 窗体中设计的应用程序的用户名和密码的帮助下获取访问令牌。我正在使用下面的代码来获取它。请给我任何更好的解决方案来获取访问令牌。
string appId = userid.ToString();
string[] extendedPermissions = new[] { "publish_stream", "offline_access" };
var oauth = new FacebookOAuthClient { ClientId = appId };
var parameters = new Dictionary<string, object> {
{ "response_type", "token" }, { "display", "popup" } };
if (extendedPermissions != null && extendedPermissions.Length > 0)
{
var scope = new StringBuilder();
scope.Append(string.Join(",", extendedPermissions));
parameters["scope"] = scope.ToString();
}
var loginUrl = oauth.GetLoginUrl(parameters);
wbTestWindow.Navigate(loginUrl);
// this webBrowser's related navigated function
private void wbTestWindow_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
FacebookOAuthResult result;
if (FacebookOAuthResult.TryParse(e.Url, out result))
{
if (result.IsSuccess)
{
var accesstoken = result.AccessToken;
}
else
{
var errorDescription = result.ErrorDescription;
var errorReason = result.ErrorReason;
}
}
}