(Facebook C# SDK) Problem getting an access token

前端 未结 3 1819
面向向阳花
面向向阳花 2021-01-22 12:01

I\'m quite new to the Facebook C# SDK (5.0.3) which probablly is the reason for this question. Basically, I\'m trying to get the current users profile, email, photo, etc etc. B

相关标签:
3条回答
  • 2021-01-22 12:28

    You code is correct for the most part, the only piece you were missing was the "redirect_uri" parameter when calling the "ExchangeCodeForAccessToken" method. This has to match the App URL you set up when you registered your Facebook App. Otherwise, you will get the error you were receiving. You don't need the "permissions" parameter, you have already received that during the prior authorization.

     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add("redirect_uri", "http://www.yourcallbackurl.com/");
     var result = cl.ExchangeCodeForAccessToken(result.code,parameters);
    
    0 讨论(0)
  • 2021-01-22 12:29

    In both the code request and access token request the redirect_uri must be the same, this will fix the OAuthException in the end. My code is now something like:

    ...    
    if (result.IsSuccess)
    {
        var tokenresult = cl.ExchangeCodeForAccessToken(result.Code, new Dictionary<string, object> { { "redirect_uri", "<your_redirect_uri>" } });
    }
    ...
    
    0 讨论(0)
  • 2021-01-22 12:46

    I think the problem is that you never get a User Access Token you only get a App Access Token. In a standalone app you need to use the oAuth Dialog. The simplest way to do this is using the Javascript SDK.

    Facebook C# SDK has a sample that shows you how to do this. You could download the whole sample app (CSASPNETWebsite) as a startingpoint.

    0 讨论(0)
提交回复
热议问题