Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insufficient permission to post to target on behalf of the viewer

I have the following code :

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);

            }
        }

When posting I get this :

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

If I change the client.post to this :

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

It works just fine.

So why is this not working when Im about to post to a specific wall? I have set the permission on this facebook page to let everyone post. The facebook app is set to online.

like image 892
Banshee Avatar asked Aug 18 '14 10:08

Banshee


1 Answers

By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?

Im surprised that this simple task was so hard to get running and that there was vary little help to get.

like image 111
Banshee Avatar answered Oct 23 '22 00:10

Banshee