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

标签 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);
                }
            }

        }
    }

最佳答案

尝试打开文件App.Config并修改最后一行

<appsettings>

部分如下:

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

关于c# - OAuthException : (#200) The user hasn't authorized the application to perform this action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10563331/

相关文章:

c# - 每 30 秒重复一次 ping

c# - 从 SQL Server 2008 到 PictureBox 的图像加载失败

c# - 如何关闭外部网络浏览器中的选项卡?

security - 将 DropBox 中的 OAuth 凭据安全地存储在数据库中以供以后使用

c# - 使用 QueryPerformanceFrequency() 和 QueryPerformanceCounter() 将我的 C++ 代码转换为 C#?

c# - 变量 previousValue 返回 NullReferenceException : Object not set to an instance of object

oauth - 为客户端获取服务器身份验证访问 token 以与谷歌分析一起使用的正确方法

Facebook c# sdk 获取用户电子邮件

facebook-c#-sdk - 使用Facebook C#SDK进行身份验证

facebook-c#-sdk - 使用 Facebook 帐户登录网站