post on facebook using asp.net c#

May 17 2013 10:56 AM
this is the code i am using to post on facebook wall,
but i am getting error at last line as this plz help me

/*
    'Facebook.FacebookClient' does not contain a definition for 'Post' and no extension method 'Post' accepting a first argument of type 'Facebook.FacebookClient' could be found (are you missing a using directive or an assembly reference?)
*/
            string app_id = "aaaa";

            string app_secret = "aaa";

            string scope = "publish_stream,manage_pages";


            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,> tokens = new Dictionary<string,>();
                Dictionary<string,> dict = new Dictionary<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('&'))
                    {
                        tokens.Add(token.Substring(0, token.IndexOf("=")),
                            token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    }
                }

                string access_token = tokens["access_token"];
                dict.Add(access_token, null);

                var client = new FacebookClient(dict);
                
                client.Post("/me/feed", new { message = bodymessage });

Answers (1)