Problems when migrating from Facebook SDK v5.4 to alpha v6

蹲街弑〆低调 提交于 2020-01-26 04:35:07

问题


I am using the following code after I login, which worked on 5.4.1, but now it isn't working as expected.

FacebookOAuthResult pResult;
if (m_pClient.TryParseOAuthCallbackUrl(e.Uri, out pResult))
{
  if (pResult.IsSuccess)
  {
    //handle if success
  }
  else
  {
  //handle if failed
  }
}

I migrated the FacebookOAuthClient to FacebookClient and after migrating everything this does not work.

My login code is as follows. I have tried both the old way and the new way, but both are not working. The commented portion is my legacy code that worked for 5.4 Can you please help me see what I am doing wrong?

//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();
//}

this is code added for 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);

回答1:


I would recommend you look at the winforms sample at https://github.com/facebook-csharp-sdk/facebook-winforms-sample

    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);
    }


来源:https://stackoverflow.com/questions/9447482/problems-when-migrating-from-facebook-sdk-v5-4-to-alpha-v6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!