[英]How to login to facebook using DotNetOpenAuth
var facebookClient = new FacebookClient
{
ClientIdentifier = "appId",
ClientSecret = "appSecret"
};
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
if (authorization == null)
{
// Kick off authorization request
facebookClient.RequestUserAuthorization();
}
else
{
var request =
WebRequest.Create("https://graph.facebook.com/me?access_token=" +
Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var graph = FacebookGraph.Deserialize(responseStream);
lblFacebookUserName.Text = HttpUtility.HtmlEncode(graph.Name);
}
}
}
the line 线
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
is always return null
始终返回
null
I'm no expert but isn't it because you always have a new FacebookClient which has never requested user authorization? 我不是专家,不是吗,因为您始终拥有一个从未请求用户授权的新FacebookClient? Your workflow seems strange to me...
您的工作流程对我来说似乎很奇怪...
Does this make any difference: 这有什么区别吗?
var facebookClient = new FacebookClient
{
ClientIdentifier = "appId",
ClientSecret = "appSecret"
};
// Kick off authorization request, as have a new client that needs to be authorised
facebookClient.RequestUserAuthorization();
// get the result of the authorization
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
if (authorization == null)
{
//throw not authorized exception or whatever
}
else
{
var request =
WebRequest.Create("https://graph.facebook.com/me?access_token=" +
Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var graph = FacebookGraph.Deserialize(responseStream);
lblFacebookUserName.Text = HttpUtility.HtmlEncode(graph.Name);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.