从wp8 app在Facebook上分享消息时出现权限屏幕

时间:2014-06-13 10:36:38

标签: c# facebook windows-phone-8 facebook-sdk-4.0

我需要在wp8上在facebook上分享一条消息。我附上了我的Main.xaml截图。

This is view of the Main.xaml

单击“共享”按钮时,首先登录Facebook,然后请求获得应用程序的权限。我使用以下代码。

 private FacebookSession session;
    private async Task Authenticate()
    {
        string message = String.Empty;
        try
        {
            session = await App.FacebookSessionClient.LoginAsync("user_about_me,publish_actions,read_stream");

            App.AccessToken = session.AccessToken;
            App.FacebookId = session.FacebookId;

            Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/Share/LandingPage.xaml", UriKind.Relative)));
        }
        catch (InvalidOperationException e)
        {
            message = "Login failed! Exception details: " + e.Message;
            MessageBox.Show(message);
        }
}

然后在LandingPage.xaml的Loading方法中,使用以下代码发布消息。

    private async void LandingPage_Loaded(object sender, RoutedEventArgs e)
    {
        FacebookClient client = new FacebookClient(App.AccessToken);

        var parameters = new Dictionary<string, object>();
        parameters.Add("message", "First test post using Facebook login");

        await client.PostTaskAsync("me/feed", parameters);
    }

当我运行应用程序时,成功登录Facebook,但权限屏幕显示如下。 screenshot of the permission page

点击确定。然后发生错误。

(OAuthException - #200) (#200) The user hasn't authorized the application to perform this action

我尽力解决这个问题,但我失败了。如果有人有想法解决这个问题。请帮帮我

谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您缺少访问令牌请求中的请求代码。

dynamic result = facebookClient.Get("oauth/access_token", new
{
    client_id = appId,
    client_secret = appSecret,
    grant_type = "authorization_code"
    redirect_uri = Request.Url.AbsoluteUri,
    code = Request["code"]
});