使用c#asp.net发布在Facebook墙上 [英] Post on facebook wall using c# asp.net

查看:82
本文介绍了使用c#asp.net发布在Facebook墙上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来在Facebook墙上发布的代码,

但我在最后一行收到错误,因为这个PLZ帮助我

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

已添加代码块[/ Edit]

Code block added[/Edit]

推荐答案

您可能需要查看此页 [ ^ ]。



欢呼,

Marco
You might want to have a look onto this page[^].

cheers,
Marco


Facebook可能使用OAuth 1.0。要与Facebook进行互动,您的代码必须遵循OAuth客户端协议。 DotNetOpenAuth是一个流行的OAuth库。它还提供了与google,hotmail,facebook等交互的示例代码。您可以在代码中使用此库。你在这做什么可能是正确的。但我不熟悉这种方法。我使用过DotNetOpenAuth库并且工作正常。



http://dotnetopenauth.net/ [ ^ ]
Facebook probably uses OAuth 1.0. To interact with facebook, your code has to follow OAuth client protocol. DotNetOpenAuth is a popular OAuth library. It also provides sample codes to interact with google, hotmail, facebook etc. You may use this library in your code. What you are doing here might be correct. But I am not familiar of such approach. I have used DotNetOpenAuth library and it worked fine.

http://dotnetopenauth.net/[^]


这篇关于使用c#asp.net发布在Facebook墙上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆