问题
Its very simple question, I'm new to this and I can't understand the problem , I am trying to get the user name and display it in a label , when i try this code to get the access token it doesn't enter the condition :
it enters the event of (browser_navigated
) but not the Conditions in , anyone knows whats the problem ?
private void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult result;
if (FacebookOAuthResult.TryParse(e.Uri, out result))
{
if (result.IsSuccess)
{
var accesstoken = result.AccessToken;
}
else
{
var errorDescription = result.ErrorDescription;
var errorReason = result.ErrorReason;
}
}
回答1:
There is an annoying bug in wpf browser control which ignores everything after #. (This is only for web browser controls based on wpf so it is present in silverlight and wp7 web browser controls as well.)
Facebook returns access token as part of url fragment.
https://url.com#access_token=....
Due to the bug, when you pass e.Uri
as a parameter it doesn't part #access_token=..
thus fb c# sdk thinks it is not a valid oauth callback url and thus TryParse
always returns false.
Solution:
Either use the winforms browser control for login or set response_type
as code token
and then exchange code for access token.
来源:https://stackoverflow.com/questions/9044657/facebook-username-wpf