OAuthException:(#200)用户尚未授权应用程序执行此操作

时间:2012-05-12 11:32:42

标签: c# oauth facebook-c#-sdk

使用Facebook C#SDK,当我尝试发布状态更新时收到以下错误:  OAuthException:(#200)用户尚未授权应用程序执行此操作

我只对某些用户收到此错误。对于其他一些,状态正在更新。应用程序成功获取所有用户的访问权限。

这是完整的代码:

public partial class Authorize : Form
    {
        public Authorize()
        {
            InitializeComponent();

        }

        public string ApplicationId 
        { 
            get 
            { 
                return ConfigurationManager.AppSettings["ApplicationId"]; 
            } 
        }

        public string ExtendedPermissions 
        { 
            get
            {
                return ConfigurationManager.AppSettings["ExtendedPermissions"];
            } 
        }

        public string AppSecret
        {
            get
            {
                return ConfigurationManager.AppSettings["ApplicationSecret"];
            }
        }

        public string AccessToken { get; set; }

        private void LoadAuthorize(object sender, EventArgs e)
        {
            var destinationURL = String.Format(
                @"https://www.facebook.com/dialog/oauth?client_id={0}&scope={1}&redirect_uri=http://www.facebook.com/connect/login_success.html&response_type=token",
                this.ApplicationId,
                this.ExtendedPermissions);
            webBrowser.Navigated += WebBrowserNavigated;
            webBrowser.Navigate(destinationURL);
        }

        private void WebBrowserNavigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            // get token
            var url = e.Url.Fragment;
            if (url.Contains("access_token") && url.Contains("#"))
            {
                this.Hide();
                url = (new Regex("#")).Replace(url, "?", 1);
                this.AccessToken = System.Web.HttpUtility.ParseQueryString(url).Get("access_token");
                //MessageBox.Show(facebookCore.AccessToken);
                try
                {
                    //var facebooking = new FacebookingTest(facebookCore.AccessToken);
                    //facebooking.UpdateStatus();
                    var fb = new FacebookClient(this.AccessToken);
                    dynamic result = fb.Post("me/feed", new { message = "Hi..Test33" });
                    var newPostId = result.id;
                }
                catch (Exception exception)
                {
                    Console.Write(exception);
                }
            }

        }
    }

1 个答案:

答案 0 :(得分:2)

尝试打开文件App.Config并修改

的最后一行
<appsettings>

部分如下:

<add key="ExtendedPermissions" value="offline_access,publish_stream,publish_actions" />