如何在窗口电话7中注销FaceBook

时间:2012-02-27 10:02:30

标签: facebook windows-phone-7

我在Windows Phone上退出Facebook时遇到问题。我有登录的代码,但我无法退出。有人可以告诉我如何在Windows Phone上退出Facebook吗?

这是登录代码:

private FacebookClient _asyncFbClient;
        private string _appID = "";
        private string _appSecret = "";

        private void StartFacebookLogin(object sender, RoutedEventArgs e)
        {
            string[] extendedPermissions = new[] { "user_about_me", "publish_stream", "email" };
            FacebookClient fb = new FacebookClient();

            var oauth = new FacebookOAuthClient { AppId = _appID, AppSecret = _appSecret };
            var logout = new FacebookUser();

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

            var loginUrl = oauth.GetLoginUrl(parameters);
            webBrowser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(CheckForAuth);
            webBrowser.Navigate(loginUrl);

        }

        private void CheckForAuth(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            FacebookOAuthResult result;
            if (FacebookOAuthResult.TryParse(e.Uri, out result))
            {
                if (result.IsSuccess)
                {
                    IsolatedStorageSettings Settings = IsolatedStorageSettings.ApplicationSettings;
                    MessageBox.Show(result.AccessToken);
                    access = result.AccessToken;
                    if (Settings.Contains("MyFacebookAccessToken1"))
                        Settings["MyFacebookAccessToken1"] = result.AccessToken;
                    else
                        Settings.Add("MyFacebookAccessToken1", result.AccessToken);
                    Settings.Save();
                    _asyncFbClient = new FacebookClient(result.AccessToken);

                    _asyncFbClient.GetCompleted += new EventHandler<FacebookApiEventArgs>(_asyncFbClient_GetCompleted);
                    _asyncFbClient.GetAsync("/me");

                }
            }
        }

这是退出代码:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(linkUrl);
            request.Method = "GET";
            request.BeginGetResponse(new AsyncCallback(LogoutResponse), request);
private void LogoutResponse(IAsyncResult result)
        {
            string responseData = "";
            try
            {
                HttpWebRequest request = result.AsyncState as HttpWebRequest;
                HttpWebResponse response = request.EndGetResponse(result) as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.OK)
                {
                    Stream stream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream);
                    responseData = reader.ReadToEnd();
                    //responseData = true
                }
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() => { MessageBox.Show(ex.Message); });
            }
        }

我尝试使用Facebook的注销API并获得了成功的结果,但下次打开网络浏览器时,它已经自动再次登录到Facebook。我怎样才能让它退出?

3 个答案:

答案 0 :(得分:2)

我尝试了很多工作来实现这一目标......然后Facebook终于更新了他们的文档并提供了一个很好的答案:

  

注销

     

您可以通过指导用户将用户从Facebook会话中注销   以下网址:

     

https://www.facebook.com/logout.php?next=YOUR_URL&access_token=ACCESS_TOKEN   YOUR_URL必须是您网站域中的网址,如中所定义   开发者应用程序

来自http://developers.facebook.com/docs/authentication/

答案 1 :(得分:0)

没有FB Logout,它已被删除。

你最好的办法是忘记你的证件。

答案 2 :(得分:0)

Facebook PHP SDK使用如下函数:

public function getLogoutUrl($params=array()) {
  return $this->getUrl(
  'www',
  'logout.php',
  array_merge(array(
    'next' => $this->getCurrentUrl(),
    'access_token' => $this->getAccessToken(),
  ), $params)
  );
}

创建一个类似以下的URL:
https://www.facebook.com/logout.php?next= {YOUR_ENCODED_URL}&安培; =的access_token {YOUR_ACCESS_TOKEN}

我认为编码的URL必须由access_token所属的应用程序拥有。 如果您正确获得该URL,它将起作用(仅针对我的一个应用程序尝试过)。

我不是百分百确定它是否适用于Windows-phone,但你可以尝试一下。