c# - 没有足够的权限代表查看者发布目标

标签 c# facebook facebook-graph-api

我有以下代码:

private void CheckAuthorization()
        {
            string app_id = "x";
            string app_secret = "x";
            string scope = "publish_stream,publish_actions";

            if (Request["code"] == null)
            {
                Response.Redirect(string.Format(
                    "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                    app_id, Request.Url.AbsoluteUri, scope));
            }
            else
            {
                Dictionary<string, string> tokens = new Dictionary<string, string>();

                string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                    app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    string vals = reader.ReadToEnd();

                    foreach (string token in vals.Split('&'))
                    {
                        //meh.aspx?token1=steve&token2=jake&...
                        tokens.Add(token.Substring(0, token.IndexOf("=")),
                            token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    }
                }

                string access_token = tokens["access_token"];

                var client = new FacebookClient(access_token);

                //client.Post("/me/feed", new { message = "A simple test" });

                var args = new Dictionary<string, object>();
                args["message"] = "abc";
                args["caption"] = "This is caption!";
                args["description"] = "This is description!";
                args["name"] = "This is name!";
                args["picture"] = "picutre";
                args["link"] = "http://www.bradspel.net/";

                client.Post("/1418771281723422/feed", args);

            }
        }

发帖时我得到这个:

(OAuthException - #200) (#200) Insufficient permission to post to target on behalf of the viewer

如果我将 client.post 更改为:

client.Post("/me/feed", args);

它工作得很好。

那么,当我要发布到特定的墙上时,为什么这不起作用?我已经在这个facebook页面上设置了允许所有人发帖的权限。 Facebook 应用程序设置为在线。

最佳答案

通过创建扩展页面 token 并使用它来使帖子一切正常。看到这个:How to get Page Access Token by code?

令我惊讶的是,这个简单的任务执行起来如此困难,而且几乎没有什么帮助。

关于c# - 没有足够的权限代表查看者发布目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25361366/

相关文章:

c# - 不知道为什么我收到 InvalidCastException

c# - 也许我需要一个正则表达式?

javascript - Facebook 登录在浏览器中工作正常,但不适用于带有 phonegap 的 Android

android - Android 中的 Facebook SDK

facebook - 使用 Facebook API 时定义和存储自定义数据

javascript - 我在哪里可以学习如何为非 Canvas 应用程序/网站实现 "invite your facebook friends"对话框?

c# - 预 ASP.NET Core MVC 应用程序中的 Razor 标记帮助程序

ruby-on-rails - Open Graph 标题错误?

ios - 我必须根据我来自 App Delegate 中的社交网络来调用这两个函数

c# - 有没有办法让某些事情仅在从特定线程调用时才发生?