Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

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

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...