2013-02-28 80 views
1

我使用C#的Facebook SDK在我的WP7的應用程序開始,和它的作品,但我只能登錄一次。我有一個類打開一個Web瀏覽器並加載一個Facebook登錄頁面。我輸入我的信息,並按照我想要的方式進行。但是,一旦我嘗試再次登錄,它會記住我之前提供的信息,並且我無法測試其他Facebook帳戶。有誰知道如何清除舊數據,以便我可以使用其他帳戶登錄?如何在Windows Phone上使用Facebook C#sdk時更改用戶?

回答

1

你需要與其他帳戶進行登錄操作嘗試執行註銷該代碼執行退出操作。

public partial class LogoutPage : PhoneApplicationPage 
{ 
    private Uri navigateUrl; 
    public FacebookOAuthResult FacebookOAuthResult { get; private set; } 

    public LogoutPage() 
    { 
     var appId = "173963872698818"; 
     string[] extendedPermissions = new[] { "user_about_me", "offline_access" }; 
     var oauth = new FacebookOAuthClient { AppId = appId }; 

     var parameters = new Dictionary<string, object> 
       { 
        { "response_type", "token" }, 
        { "display", "wap" } //"popup works, touch not works 
       }; 

     if (extendedPermissions != null && extendedPermissions.Length > 0) 
     { 
      var scope = new StringBuilder(); 
      scope.Append(string.Join(",", extendedPermissions)); 
      parameters["scope"] = scope.ToString(); 
     } 

     var loginUrl = oauth.GetLoginUrl(parameters); 
     var logoutParameters = new Dictionary<string, object> 
             { 
              { "next", loginUrl } 
             };    

     //Redirect to the following url. 
     // https://www.facebook.com/logout.php?next=YOUR_URL&access_token=ACCESS_TOKEN 
     //this.navigateUrl = oauth.GetLogoutUrl(logoutParameters); 

     var a = App.Current as App; 
     string absoluteURI = " https://www.facebook.com/logout.php?next=http://www.fengshuiexplorer.host56.com&access_token=" + a.myToken; 

     this.navigateUrl = new Uri(absoluteURI); 

     InitializeComponent(); 
    } 


    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) 
    { 
     webBrowser1.Navigate(this.navigateUrl); 
    } 

    private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) 
    { 
     FacebookOAuthResult result; 
     if (FacebookOAuthResult.TryParse(e.Uri, out result)) 
     { 
      this.FacebookOAuthResult = result; 
      var a = App.Current as App; 
      a.isLoggedIn = false; 
      NavigationService.GoBack(); 
     } 
     else 
     { 
      this.FacebookOAuthResult = null; 
     } 
    } 
} 
0

或者你可以嘗試下面的代碼片段給你打電話再次登錄。

await new WebBrowser().ClearCookiesAsync(); 
相關問題