2012-02-25 44 views
-1

我登錄後使用以下代碼,該代碼在5.4.1上工作,但現在不能按預期工作。從Facebook SDK v5.4遷移到alpha v6時出現問題

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

我將FacebookOAuthClient遷移到FacebookClient,遷移後的一切都無法工作。

我的登錄代碼如下。我已經嘗試了舊的方式和新的方式,但都不起作用。評論的部分是我的遺留代碼,爲5.4工作你能幫我看看我做錯了什麼?

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

此加入代碼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); 

回答

2

我建議你看一下的WinForms樣品在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); 
    } 
+0

我回滾我的代碼到5.4版本,一切都在該版本中正常並按預期工作。我會等到v6超出alpha。 – 2012-02-27 15:33:58

相關問題